26 #include <Classes.hpp>
27 #include <Controls.hpp>
28 #include <StdCtrls.hpp>
30 #include <Buttons.hpp>
31 #include <ExtCtrls.hpp>
33 #include <Dialogs.hpp>
34 #include <Graphics.hpp>
35 #include <ComCtrls.hpp>
52 #pragma package(smart_init)
62 TTrain::TTrain(
int Caller,
int RearStartElementIn,
int RearStartExitPosIn, AnsiString InputCode,
int StartSpeedIn,
int MassIn,
double MaxRunningSpeedIn,
63 double MaxBrakeRateIn,
double PowerAtRailIn,
TTrainMode TrainModeIn,
TTrainDataEntry *TrainDataEntryPtrIn,
int RepeatNumberIn,
int IncrementalMinutesIn,
64 int IncrementalDigitsIn,
int SignallerMaxSpeedIn) : RearStartElement(RearStartElementIn), RearStartExitPos(RearStartExitPosIn), HeadCode(InputCode),
65 StartSpeed(StartSpeedIn), Mass(MassIn), MaxRunningSpeed(MaxRunningSpeedIn), MaxBrakeRate(MaxBrakeRateIn), PowerAtRail(PowerAtRailIn),
66 TrainMode(TrainModeIn), TrainDataEntryPtr(TrainDataEntryPtrIn), RepeatNumber(RepeatNumberIn), IncrementalMinutes(IncrementalMinutesIn),
67 IncrementalDigits(IncrementalDigitsIn), SignallerMaxSpeed(SignallerMaxSpeedIn)
78 AnsiString(RearStartExitPosIn) +
"," + AnsiString(InputCode) +
"," + AnsiString(StartSpeedIn) +
"," + AnsiString(MassIn) +
"," +
79 AnsiString(TrainModeIn));
123 for(
int x = 0; x < 4; x++)
132 for(
int x = 0; x < 4; x++)
141 for(
int x = 0; x < 4; x++)
146 for(
int x = 0; x < 4; x++)
150 for(
int x = 0; x < 3; x++)
187 for(
int x = 0; x < 4; x++)
234 throw Exception(
"Error in attempting to delete FrontCodePtr");
238 for(
int x = 0; x < 4; x++)
242 throw Exception(
"Error in attempting to delete BackgroundPtr[" + AnsiString(x) +
"]");
247 for(
int x = 0; x < 4; x++)
251 throw Exception(
"Error in attempting to delete HeadCodeGrPtr[" + AnsiString(x) +
"]");
280 int NextElementPosition, NextEntryPos, ElementLength, SpeedLimit;
346 bool TempDerail =
false;
392 else if((NextElementPosition > -1) && (NextEntryPos > -1))
463 throw Exception(
"Error, LeadElement Exit Connection is NotSet");
473 for(
int x = 0; x < 4; x++)
480 for(
int x = 0; x < 4; x++)
723 if((random(RandRange)) == 0)
738 int LockedVectorNumber;
975 if(BufferLocation ==
"")
980 if((BufferLocation ==
"") || (BufferLocation != ExpectedLocation))
1042 int NextElementPosition, NextEntryPos;
1066 NextElementPosition = -1;
1069 if((NextElementPosition > -1) && (NextEntryPos > -1))
1183 AnsiString StationName;
1194 throw Exception(
"Error - Stopped at through station but neither lead nor mid elements have a name");
1207 if((NextElementPosition > -1) && (NextEntryPos > -1))
1330 if(NextElementPosition > -1)
1367 AnsiString Loc =
"";
1368 bool LocNamed =
false;
1397 Loc =
"outside railway";
1429 NextElementPosition = -1;
1440 if((NextElementPosition > -1) && (NextEntryPos > -1) && !
SPADFlag)
1458 if((NextElementPosition > -1) && (NextEntryPos > -1))
1496 FirstPair.second).
GetELink() == TempELink))
1501 SecondPair.second).
GetELink() == TempELink))
1515 FirstPair.second).
GetELink() == TempELink))
1520 SecondPair.second).
GetELink() == TempELink))
1534 FirstPair.second).
GetELink() == TempELink))
1539 SecondPair.second).
GetELink() == TempELink))
1569 ContinuationAutoSigEntry.
RouteNumber = RouteNumber;
1572 int NewLastElement = 0, NewLastExitPos = 0;
1590 if(NewLastElement == -1)
1593 throw Exception(
"Error, Connection = -1 in Continuation loop in UpdateTrain");
1596 if(NewLastExitPos == -1)
1598 throw Exception(
"Error, ConnLinkPos = -1 in Continuation loop in UpdateTrain");
1600 LastElement = NewLastElement;
1601 LastExitPos = NewLastExitPos;
1604 if(CumDistance < 1200)
1610 int FirstDistance = 0;
1611 if(CumDistance >= 1200)
1613 FirstDistance = 100;
1617 FirstDistance = 1200 - CumDistance;
1619 if(FirstDistance < 100)
1621 FirstDistance = 100;
1647 if(VectorIT->RouteNumber == RouteNumber)
1694 LockedVectorNumber)))
1853 for(
int x = 0; x < 4; x++)
1860 for(
int x = 0; x < 4; x++)
1886 if((LeadElementTrainID > -1) && (LeadElementTrainID !=
TrainID))
1891 if(OtherTrainEntryPos == -1)
1893 throw Exception(
"Error - OtherTrainEntryPos not set");
1912 int OtherTrainID = -1;
1913 if((MidExitLinkNum == 1) || (MidExitLinkNum == 3) || (MidExitLinkNum == 7) || (MidExitLinkNum == 9))
2004 bool StopRequired =
false;
2017 int NextElementEntryPos = -1;
2018 int NextElementExitPos = -1;
2019 bool TrainOnNextElement =
false;
2020 bool StopSignalAtNextElement =
false;
2021 if(ForwardConnection)
2029 StopSignalAtNextElement = ((NextTrackElement.
Config[NextElementExitPos] ==
Signal) && (NextTrackElement.
Attribute == 0));
2032 if(TrainAtStopLinkPos1 || TrainAtStopLinkPos2 || (ForwardConnection && (TrainOnNextElement || StopSignalAtNextElement)))
2087 throw Exception(
"Error, Straddle shouldn't be LeadMid prior to resetting at exit from UpdateTrain");
2300 if(Code.Length() != 4)
2304 for(
int x = 1; x < 5; x++)
2311 for(
int x = 0; x < 4; x++)
2475 throw Exception(
"Error in GetOffsetValues - Link value wrong");
2488 if((EntryLink == 1) || (EntryLink == 2) || (EntryLink == 4) || (EntryLink == 7))
2503 AnsiString(
VOffset) +
"," + AnsiString(Element) +
"," + AnsiString(EntryPos) +
"," +
HeadCode);
2512 TRect SourceRect, DestRect;
2514 DestRect.init(0, 0, 8, 8);
2517 Graphics::TBitmap *TempGraphic =
new Graphics::TBitmap;
2519 TempGraphic->PixelFormat = pf8bit;
2520 TempGraphic->Width = 16;
2521 TempGraphic->Height = 16;
2527 TempGraphic->Transparent =
true;
2531 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2532 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2538 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2546 else if(TempElement.
SpeedTag == 89)
2550 else if(TempElement.
SpeedTag == 90)
2554 else if(TempElement.
SpeedTag == 91)
2558 else if(TempElement.
SpeedTag == 92)
2562 else if(TempElement.
SpeedTag == 93)
2566 else if(TempElement.
SpeedTag == 94)
2570 else if(TempElement.
SpeedTag == 95)
2574 TempGraphic->Transparent =
true;
2578 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2579 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2581 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2588 for(
int x = 0; x < 40; x++)
2603 TempGraphic->Transparent =
true;
2607 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2608 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2610 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2624 TempGraphic->Transparent =
true;
2628 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2629 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2633 TempGraphic->Canvas->Draw(0, 0, TempElement.
GraphicPtr);
2636 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2641 TempGraphic->Transparent =
true;
2645 int BDVectorPos = -1;
2654 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2659 TempGraphic->Transparent =
true;
2663 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2664 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2666 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2672 TempGraphic->Transparent =
true;
2676 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2677 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2679 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2945 throw Exception(
"Error, same train on two different bridge tracks");
2991 AnsiString(EntryPos) +
"," +
HeadCode);
3008 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in SetTrainElementID");
3027 AnsiString(EntryPos) +
"," +
HeadCode);
3036 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in ResetTrainElementID");
3069 AnsiString(ElementEntryPos) +
"," + AnsiString(
HOffset) +
"," + AnsiString(
VOffset) +
"," + AnsiString(StraddleValue) +
"," +
HeadCode);
3070 int LockedVectorNumber;
3083 TRect SourceRect, DestRect;
3084 DestRect.init(0, 0, 8, 8);
3091 int FirstELink, SecondELink = -1;
3094 if(RoutePair2.first > -1)
3103 if(SecondELink == -1)
3105 throw Exception(
"Error - Second ELink should be set but isn't in PlotAlternativeTrackRouteGraphic [1]");
3110 throw Exception(
"Error - First & Second ELinks have same value in PlotAlternativeTrackRouteGraphic");
3120 Graphics::TBitmap *DestGraphic =
new Graphics::TBitmap;
3121 DestGraphic->PixelFormat = pf8bit;
3122 DestGraphic->Width = 8;
3123 DestGraphic->Height = 8;
3124 DestGraphic->Transparent =
true;
3127 DestGraphic->Canvas->CopyRect(DestRect, RouteElement.
GetRouteEXGraphicPtr()->Canvas, SourceRect);
3136 PrefDirElement, LockedVectorNumber))
3151 if(ElementEntryPos > 1)
3173 AnsiString(EntryPos) +
"," +
HeadCode);
3175 bool WrongRoute =
false;
3201 int LinkNumber = TrackElement.
Link[EntryPos];
3202 if((LinkNumber == 1) || (LinkNumber == 3) || (LinkNumber == 7) || (LinkNumber == 9))
3207 bool LogActionErrorCalled =
false;
3217 LogActionErrorCalled =
true;
3234 else if(LinkNumber == 3)
3242 LogActionErrorCalled =
true;
3259 else if(LinkNumber == 7)
3267 LogActionErrorCalled =
true;
3284 else if(LinkNumber == 9)
3292 LogActionErrorCalled =
true;
3324 else if((RouteElement.
GetELinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3329 else if((RouteElement.
GetELinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3339 else if((RouteElement.
GetXLinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3344 else if((RouteElement.
GetXLinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3353 throw Exception(
"Error, Element in route but no route found in CheckAndCancelRouteForWrongEndEntry");
3374 bool ColourError =
false, ColourError2 =
false;
3379 ColourError2 =
true;
3381 for(
int x = 0; x < 4; x++)
3386 ColourError2 =
true;
3392 "ERROR: Colour depth insufficient to display train colours properly. Please ensure that the 'safe' (web) palette of 256 colours can be displayed");
3396 for(
int x = 0; x < 4; x++)
3483 AnsiString(EntryPos) +
"," +
HeadCode);
3484 int EntryHalfLength, CurrentElementHalfLength, NextElementHalfLength, CumulativeLength = 0, CurrentTrackVectorPosition = TrackVectorPosition;
3485 int DistanceAtHalfBraking, DistanceAtThreeQuarterBraking, ExitPos, NextTrackVectorPosition, NextEntryPos;
3486 bool RedSignalFlag =
false, BuffersFlag =
false, StationFlag =
false, BuffersOrContinuationNowFlag =
false, ContinuationNextFlag =
false,
3487 TrainInFrontInSignallerModeFlag =
false;
3488 double LimitingSpeed, FrontElementMaxSpeed, MaxExitSpeedAtHalfBrakingSquared, MaxExitSpeedAtHalfBraking, NextSpeedLimit, TempBrakeRate;
3489 double ExitSpeedHalfSquared, ExitSpeedFullSquared;
3490 bool SignallerStopRequired =
false;
3501 if(CurrentTrackVectorPosition > -1)
3505 if((EntryPos == 0) || (EntryPos == 2))
3518 else if(EntryPos == 1)
3542 EntryHalfLength = CurrentElementHalfLength;
3547 throw Exception(
"Error - CurrentTrackVectorPosition < 0 in SetTrainMovementValues");
3551 throw Exception(
"Error - HalfLength or SpeedLimit < 0 in SetTrainMovementValues");
3598 FrontElementMaxSpeed = LimitingSpeed;
3628 double ExitSpeedAtMaxBraking;
3633 ExitSpeedAtMaxBraking = 0;
3643 if(ExitSpeedAtMaxBraking > LimitingSpeed)
3645 SpeedToUse = ExitSpeedAtMaxBraking;
3649 SpeedToUse = LimitingSpeed;
3664 RedSignalFlag =
false;
3665 BuffersFlag =
false;
3666 StationFlag =
false;
3667 BuffersOrContinuationNowFlag =
false;
3668 ContinuationNextFlag =
false;
3671 CumulativeLength += (2 * CurrentElementHalfLength);
3674 SignallerStopRequired =
true;
3696 bool StopRequired =
false;
3710 StationFlag =
false;
3716 BuffersOrContinuationNowFlag =
true;
3718 if(!BuffersOrContinuationNowFlag && !BuffersFlag && !StationFlag)
3722 if((EntryPos == 0) || (EntryPos == 2))
3744 if(NextTrackVectorPosition > -1)
3749 if((NextEntryPos == 0) || (NextEntryPos == 2))
3762 else if(NextEntryPos == 1)
3775 if(NextEntryPos > 1)
3789 throw Exception(
"Error - Trying to access NextTrackVectorPosition when none present in SetTrainMovementValues");
3801 RedSignalFlag =
true;
3823 TrainInFrontInSignallerModeFlag =
true;
3847 if(RedSignalFlag || BuffersFlag || StationFlag || TrainInFrontInSignallerModeFlag || SignallerStopRequired ||
StepForwardFlag)
3859 double MaxHalfSpeed;
3863 if(MaxHalfSpeedAtHalfBraking > FrontElementMaxSpeed)
3865 MaxHalfSpeed = FrontElementMaxSpeed;
3869 MaxHalfSpeed = MaxHalfSpeedAtHalfBraking;
3877 bool HalfSpeedLimited =
false;
3881 HalfSpeedLimited =
true;
3911 if(HalfSpeedLimited)
3936 if(SignallerStopRequired)
3952 int TempMaxExitSpeed;
3955 if(MaxExitSpeedAtHalfBrakingSquared < 10)
3957 MaxExitSpeedAtHalfBraking = 0;
3961 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
3965 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
3967 TempMaxExitSpeed = FrontElementMaxSpeed;
3971 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
3983 if(ExitSpeedHalfSquared < 10)
3993 if(ExitSpeedFullSquared < 10)
4065 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4066 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4090 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4091 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4101 if(!BuffersOrContinuationNowFlag)
4103 if(NextSpeedLimit < LimitingSpeed)
4105 LimitingSpeed = NextSpeedLimit;
4109 int TempMaxExitSpeed;
4113 if(MaxExitSpeedAtHalfBrakingSquared < 10)
4115 MaxExitSpeedAtHalfBraking = 0;
4119 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
4121 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
4123 TempMaxExitSpeed = FrontElementMaxSpeed;
4127 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
4138 TempBrakeRate = ((
EntrySpeed *
EntrySpeed) - (LimitingSpeed * LimitingSpeed)) / 3.6 / 3.6 / 2 / CumulativeLength;
4151 if(!BuffersOrContinuationNowFlag)
4153 CurrentTrackVectorPosition = NextTrackVectorPosition;
4154 EntryPos = NextEntryPos;
4155 CurrentElementHalfLength = NextElementHalfLength;
4158 ContinuationNextFlag =
true;
4162 while(((CumulativeLength -
FrontElementLength) < DistanceAtHalfBraking) && ((!BuffersOrContinuationNowFlag && !ContinuationNextFlag) ||
4182 if(ExitSpeedHalfSquared < 10)
4192 if(ExitSpeedFullSquared < 10)
4255 double DeltaExitTimeToMaxInSecs;
4256 double DistanceToMax;
4265 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4267 DistanceToMax = EntryHalfLength;
4270 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4271 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4288 double DeltaExitTimeToMaxInSecs;
4289 double DistanceToMax;
4298 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4300 DistanceToMax = EntryHalfLength / 2;
4303 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4304 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4315 if(ExitSpeedHalfSquared < 10)
4325 if(ExitSpeedFullSquared < 10)
4344 if((EntryPos == 0) || (EntryPos == 2))
4366 if(NextTrackVectorPosition > -1)
4368 int NextElementLength;
4369 if(NextEntryPos > 1)
4377 double NextStoppingSpeed = sqrt(3.6 * 3.6 * 2 *
BrakeRate * NextElementLength);
4513 if((Ptr->Command ==
"cdt") || (Ptr->FormatType ==
Repeat))
4517 if((Ptr->ArrivalTime > TDateTime(-1)) && (Ptr->LocationName == Name))
4526 if((Ptr->EventTime > TDateTime(-1)) && (Ptr->LocationName == Name) && (Ptr->Command ==
"pas"))
4551 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition;
4569 CurrentTrackVectorPosition).
Attribute != 4))
4608 if((EntryPos == 0) || (EntryPos == 2))
4630 CurrentTrackVectorPosition = NextTrackVectorPosition;
4631 EntryPos = NextEntryPos;
4655 throw Exception(
"Error - failed to set ReturnVal in ClearToNextSignal()");
4679 bool PlatformFoundFlag =
false, StopRequired =
false, SkipRouteCheck =
false, RouteOrPartRouteSet =
false;
4680 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition, ElementNumber = 0, Distance = 0;
4681 int RouteStartPosition;
4683 int PlatformPosition;
4685 int EntryPos =
LeadEntryPos, ExitPos, NextEntryPos, RouteID;
4701 if(Distance > (4000 + LeadElementDistance))
4724 if(OtherTrain.
LeadElement == CurrentTrackVectorPosition)
4727 if((OtherCommand ==
"Fjo") || (OtherCommand ==
"jbo") || (OtherCommand ==
"cdt") || (OtherCommand ==
"Frh") ||
4773 if(!PlatformFoundFlag)
4775 PlatformPosition = CurrentTrackVectorPosition;
4778 PlatformFoundFlag =
true;
4794 if((EntryPos == 0) || (EntryPos == 2))
4838 if(ElementNumber < 2)
4840 SkipRouteCheck =
true;
4844 SkipRouteCheck =
false;
4846 if(ElementNumber == 1)
4848 RouteStartPosition = CurrentTrackVectorPosition;
4858 if(ElementNumber > 1)
4862 RouteOrPartRouteSet =
true;
4866 RouteOrPartRouteSet =
false;
4869 if(!SkipRouteCheck && !RouteOrPartRouteSet)
4876 int ExitLink = CurrentTrackElement.
Link[ExitPos];
4877 if((ExitLink == 1) || (ExitLink == 3) || (ExitLink == 7) || (ExitLink == 9))
4889 Distance += CurrentTrackElement.
Length01;
4893 Distance += CurrentTrackElement.
Length23;
4895 NextTrackVectorPosition = CurrentTrackElement.
Conn[ExitPos];
4896 NextEntryPos = CurrentTrackElement.
ConnLinkPos[ExitPos];
4897 CurrentTrackVectorPosition = NextTrackVectorPosition;
4898 EntryPos = NextEntryPos;
4935 return(RepeatHeadCode);
4957 bool FrontValid =
false, RearValid =
false;
4958 TTrackElement FrontAdjacentTrackElement, RearAdjacentTrackElement;
4962 TrainToBeJoinedBy = NULL;
4976 int TrainToBeJoinedByID = -1;
4997 if((TrainToBeJoinedByID < 0) && RearValid)
5016 if(TrainToBeJoinedByID < 0)
5018 TrainToBeJoinedBy = NULL;
5023 if(!TrainToBeJoinedBy->
Stopped())
5025 TrainToBeJoinedBy = NULL;
5036 TDateTime TimetableNonRepeatTime,
bool Warning)
5071 AnsiString(ActionType) +
"," + LocationName +
"," +
HeadCode);
5072 AnsiString BaseLog =
"", WarningBaseLog =
"", PerfLog =
"", ActionLog =
"";
5073 int IntMinsLate = 0;
5078 ActionLog =
" arrived at ";
5087 ActionLog =
" terminated at ";
5092 ActionLog =
" departed from ";
5094 if(ActionType ==
Pass)
5096 ActionLog =
" passed ";
5100 ActionLog =
" created at ";
5102 if(ActionType ==
Enter)
5104 ActionLog =
" entered railway at ";
5106 if(ActionType ==
Leave)
5108 ActionLog =
" left railway at ";
5112 ActionLog =
" split from front to ";
5116 ActionLog =
" split from rear to ";
5120 ActionLog =
" joined by ";
5124 ActionLog =
" changed direction at ";
5128 ActionLog =
" became new service ";
5132 ActionLog =
" taken under signaller control at ";
5136 ActionLog =
" restored to timetable control at ";
5142 ActionLog =
" REMOVED FROM RAILWAY DUE TO CRASH at ";
5146 ActionLog =
" REMOVED FROM RAILWAY DUE TO DERAILMENT at ";
5150 ActionLog =
" REMOVED FROM RAILWAY at ";
5155 ActionLog =
" received signaller authority to proceed";
5159 ActionLog =
" received signaller authority to step forward";
5163 ActionLog =
" changed direction under signaller control at ";
5167 ActionLog =
" received signaller authority to pass red signal";
5171 ActionLog =
" received signaller instruction to stop";
5175 ActionLog =
" stopped on signaller instruction ";
5179 ActionLog =
" joined under signaller control by ";
5183 ActionLog =
" suffered an onboard power failure at ";
5187 ActionLog =
" failure repaired at ";
5191 ActionLog =
" left railway under signaller control at ";
5193 if(OtherHeadCode !=
"")
5195 OtherHeadCode +=
" at ";
5202 WarningBaseLog =
HeadCode + ActionLog + OtherHeadCode + LocationName;
5208 bool TimePerformance =
true;
5216 TimePerformance =
false;
5220 double MinsLate = ((double)(ActualTime -
GetTrainTime(1, TimetableNonRepeatTime))) * 1440;
5232 IntMinsLate = int(ceil(MinsLate));
5236 IntMinsLate = int(floor(MinsLate));
5238 if(IntMinsLate == 0)
5240 PerfLog =
" on time";
5242 else if(IntMinsLate == 1)
5244 PerfLog =
" 1 minute late";
5246 else if(IntMinsLate == -1)
5248 PerfLog =
" 1 minute early";
5250 else if(IntMinsLate > 1)
5252 PerfLog =
" " + AnsiString(IntMinsLate) +
" minutes late";
5254 else if(IntMinsLate < -1)
5256 int PosIntMinsLate = -IntMinsLate;
5257 PerfLog =
" " + AnsiString(PosIntMinsLate) +
" minutes early";
5259 if(LocationName.Pos(
'-') > 0)
5261 PerfLog =
"," + PerfLog;
5275 if((ActionType ==
Arrive) && (IntMinsLate == 0))
5279 else if((ActionType ==
Arrive) && (IntMinsLate > 0))
5284 else if((ActionType ==
Arrive) && (IntMinsLate < 0))
5290 else if((ActionType ==
Pass) && (IntMinsLate == 0))
5294 else if((ActionType ==
Pass) && (IntMinsLate > 0))
5299 else if((ActionType ==
Pass) && (IntMinsLate < 0))
5305 else if((ActionType ==
Leave) && (IntMinsLate == 0))
5309 else if((ActionType ==
Leave) && (IntMinsLate > 0))
5314 else if((ActionType ==
Leave) && (IntMinsLate < 0))
5320 else if((ActionType ==
Depart) && (IntMinsLate == 0))
5324 else if((ActionType ==
Depart) && (IntMinsLate > 0))
5343 AnsiString LocName =
"";
5409 if(LocationName ==
"")
5413 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5414 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5415 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5419 if(LocationName !=
"")
5427 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5432 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5446 int LeadPosA = FirstNamedElementPos;
5447 int LeadPosB = FirstNamedLinkedElementPos;
5448 int LeadPosC = SecondNamedElementPos;
5449 int LeadPosD = SecondNamedLinkedElementPos;
5451 int LeadNumAtLoc = 0;
5468 if(LeadNumAtLoc < 4)
5472 SecondNamedLinkedElementPos))
5474 FirstNamedElementPos = LeadPosA;
5475 FirstNamedLinkedElementPos = LeadPosB;
5476 SecondNamedElementPos = LeadPosC;
5477 SecondNamedLinkedElementPos = LeadPosD;
5481 int MidNumAtLoc = 0;
5498 if(LeadNumAtLoc > MidNumAtLoc)
5501 FirstNamedElementPos = LeadPosA;
5502 FirstNamedLinkedElementPos = LeadPosB;
5503 SecondNamedElementPos = LeadPosC;
5504 SecondNamedLinkedElementPos = LeadPosD;
5518 throw Exception(
"Error - LocationName not set in FrontTrainSplit");
5528 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5529 FrontTrainRearPosition = FirstNamedElementPos;
5530 RearTrainFrontPosition = SecondNamedElementPos;
5531 RearTrainRearPosition = SecondNamedLinkedElementPos;
5535 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5536 FrontTrainRearPosition = SecondNamedElementPos;
5537 RearTrainFrontPosition = FirstNamedElementPos;
5538 RearTrainRearPosition = FirstNamedLinkedElementPos;
5545 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5546 FrontTrainRearPosition = SecondNamedElementPos;
5547 RearTrainFrontPosition = FirstNamedElementPos;
5548 RearTrainRearPosition = FirstNamedLinkedElementPos;
5552 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5553 FrontTrainRearPosition = FirstNamedElementPos;
5554 RearTrainFrontPosition = SecondNamedElementPos;
5555 RearTrainRearPosition = SecondNamedLinkedElementPos;
5558 RearTrainExitPos = -1;
5559 for(
int x = 0; x < 4; x++)
5563 RearTrainExitPos = x;
5567 if(RearTrainExitPos == -1)
5569 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in FrontTrainSplit");
5571 FrontTrainExitPos = -1;
5572 for(
int x = 0; x < 4; x++)
5576 FrontTrainExitPos = x;
5580 if(FrontTrainExitPos == -1)
5582 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in FrontTrainSplit");
5585 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5592 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
5612 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
5620 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
5621 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
5622 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
5719 if(LocationName ==
"")
5723 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5724 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5725 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5729 if(LocationName !=
"")
5736 SecondNamedLinkedElementPos))
5740 SecondNamedLinkedElementPos))
5754 int LeadPosA = FirstNamedElementPos;
5755 int LeadPosB = FirstNamedLinkedElementPos;
5756 int LeadPosC = SecondNamedElementPos;
5757 int LeadPosD = SecondNamedLinkedElementPos;
5759 int LeadNumAtLoc = 0;
5776 if(LeadNumAtLoc < 4)
5780 SecondNamedLinkedElementPos))
5782 FirstNamedElementPos = LeadPosA;
5783 FirstNamedLinkedElementPos = LeadPosB;
5784 SecondNamedElementPos = LeadPosC;
5785 SecondNamedLinkedElementPos = LeadPosD;
5789 int MidNumAtLoc = 0;
5806 if(LeadNumAtLoc > MidNumAtLoc)
5809 FirstNamedElementPos = LeadPosA;
5810 FirstNamedLinkedElementPos = LeadPosB;
5811 SecondNamedElementPos = LeadPosC;
5812 SecondNamedLinkedElementPos = LeadPosD;
5826 throw Exception(
"Error - LocationName not set in RearTrainSplit");
5836 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5837 FrontTrainRearPosition = FirstNamedElementPos;
5838 RearTrainFrontPosition = SecondNamedElementPos;
5839 RearTrainRearPosition = SecondNamedLinkedElementPos;
5843 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5844 FrontTrainRearPosition = SecondNamedElementPos;
5845 RearTrainFrontPosition = FirstNamedElementPos;
5846 RearTrainRearPosition = FirstNamedLinkedElementPos;
5853 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5854 FrontTrainRearPosition = SecondNamedElementPos;
5855 RearTrainFrontPosition = FirstNamedElementPos;
5856 RearTrainRearPosition = FirstNamedLinkedElementPos;
5860 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5861 FrontTrainRearPosition = FirstNamedElementPos;
5862 RearTrainFrontPosition = SecondNamedElementPos;
5863 RearTrainRearPosition = SecondNamedLinkedElementPos;
5866 RearTrainExitPos = -1;
5867 for(
int x = 0; x < 4; x++)
5871 RearTrainExitPos = x;
5875 if(RearTrainExitPos == -1)
5877 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in RearTrainSplit");
5879 FrontTrainExitPos = -1;
5880 for(
int x = 0; x < 4; x++)
5884 FrontTrainExitPos = x;
5888 if(FrontTrainExitPos == -1)
5890 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in RearTrainSplit");
5893 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5900 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
5920 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
5928 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
5929 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
5930 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
6069 TTrain *TrainToBeJoinedBy;
6102 double OtherBrakeForce = TrainToBeJoinedBy->
MaxBrakeRate * TrainToBeJoinedBy->
Mass;
6104 double CombinedBrakeRate = (OtherBrakeForce + OwnBrakeForce) / (TrainToBeJoinedBy->
Mass +
Mass);
6161 int RouteNumber = -1;
6169 bool FirstPass =
true;
6174 if(FirstPass && (TVPos2 != FirstRouteElementVecPos))
6277 for(
int x = 0; x < IncNum; x++)
6310 else if(Ptr->
Command ==
"jbo")
6321 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
6327 bool IncludeFER =
false;
6335 if(!IncludeFER && (Ptr->
Command ==
"Fer"))
6340 else if(IncludeFER && (Ptr->
Command ==
"Fer"))
6351 else if(Ptr->
Command ==
"Fjo")
6357 else if(Ptr->
Command ==
"Frh")
6367 else if(Ptr->
Command ==
"Frh-sh")
6418 else if(Ptr->
Command ==
"jbo")
6423 else if(Ptr->
Command ==
"cdt")
6431 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
6803 int RouteNumber = -1;
6811 bool FirstPass =
true;
6816 if(FirstPass && (TVPos2 != FirstRouteElementVecPos))
6844 ",FloatingLabelNextString" +
"," +
HeadCode);
6845 AnsiString RetStr =
"", LocationName =
"";
6849 throw Exception(
"Error - start entry in FloatingLabelNextString");
6889 else if(Ptr->
Command ==
"Fns")
6895 else if(Ptr->
Command ==
"F-nshs")
6926 RetStr =
"None, train terminated at " + Ptr->
LocationName;
6928 else if(Ptr->
Command ==
"Frh")
6930 RetStr =
"None, train terminated at " + Ptr->
LocationName;
6932 else if(Ptr->
Command ==
"Fer")
6934 AnsiString AllowedExits =
"";
6937 else if(Ptr->
Command ==
"Fjo")
6942 else if(Ptr->
Command ==
"jbo")
6947 else if(Ptr->
Command ==
"fsp")
6952 else if(Ptr->
Command ==
"rsp")
6957 else if(Ptr->
Command ==
"cdt")
6970 + AnsiString(RptNum) +
",CheckNewServiceDepartureTime," +
HeadCode);
6971 AnsiString DepTime =
"", EventTime =
"";
6972 bool CDTFlag =
false;
6976 if(AVI->Command ==
"cdt")
6981 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
6984 RetStr +=
"\nNew service splits at " + EventTime;
6988 if(AVI->Command ==
"jbo")
6991 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
6995 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
7000 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
7004 RetStr +=
"\nNew service departs at " + DepTime;
7020 ",FloatingTimetableString" +
"," +
HeadCode);
7021 AnsiString RetStr =
"", PartStr =
"";
7027 throw Exception(
"Error - start entry in FloatingTimetableString");
7030 bool FirstPass =
true;
7043 AnsiString TrainLoc =
"";
7081 AnsiString TrainLoc =
"";
7109 else if(Ptr->
Command ==
"Fns")
7115 else if(Ptr->
Command ==
"F-nshs")
7148 else if(Ptr->
Command ==
"Frh")
7152 else if(Ptr->
Command ==
"Fer")
7154 AnsiString AllowedExits =
"";
7157 else if(Ptr->
Command ==
"Fjo")
7162 else if(Ptr->
Command ==
"jbo")
7167 else if(Ptr->
Command ==
"fsp")
7172 else if(Ptr->
Command ==
"rsp")
7177 else if(Ptr->
Command ==
"cdt")
7183 RetStr = RetStr +
'\n' + PartStr;
7200 RetStr =
"Timetable finished";
7204 RetStr =
"No timetable";
7361 bool ForwardHeadCode;
7365 ForwardHeadCode =
true;
7370 ForwardHeadCode =
false;
7513 if(ColourNumber == 0)
7517 else if(ColourNumber == 1)
7521 else if(ColourNumber == 2)
7525 else if(ColourNumber == 3)
7529 else if(ColourNumber == 4)
7533 else if(ColourNumber == 5)
7537 else if(ColourNumber == 6)
7541 else if(ColourNumber == 7)
7545 else if(ColourNumber == 8)
7549 else if(ColourNumber == 9)
7553 else if(ColourNumber == 10)
7557 else if(ColourNumber == 11)
7561 else if(ColourNumber == 12)
7565 else if(ColourNumber == 13)
7569 else if(ColourNumber == 14)
7581 for(
int x = 0; x < 4; x++)
7588 for(
int x = 0; x < 4; x++)
7673 if((LocationAndMarker[1] !=
'*') && (LocationAndMarker.Length() > 6))
7676 AnsiString Location = LocationAndMarker.SubString(1, LocationAndMarker.Length() - 6);
7677 bool GiveMessagesFalse =
false;
7678 bool CheckLocationsExistInRailwayTrue =
true;
7685 AnsiString Marker = LocationAndMarker.SubString(LocationAndMarker.Length() - 5, 6);
7688 if(Marker[6] ==
'1')
8153 bool HideFlashingTrain =
true;
8156 Graphics::TBitmap *SmallTrainBitmap;
8197 HideFlashingTrain =
false;
8202 HideFlashingTrain =
false;
8207 HideFlashingTrain =
false;
8212 HideFlashingTrain =
false;
8217 HideFlashingTrain =
false;
8221 if((
LeadElement > -1) && (!HideFlashingTrain || Flash))
8225 if((
MidElement > -1) && (!HideFlashingTrain || Flash))
8249 for(
int y = 0; y < 3; y++)
8253 bool FoundFlag =
false;
8264 if(IMPair.first != IMPair.second)
8291 if((LocationName ==
"") && (
MidElement > -1))
8295 if((LocationName ==
"") && (
LagElement > -1))
8299 if(LocationName ==
"")
8301 throw Exception(
"Error - Location name not set in TrainAtLocation");
8312 for(
int x = 0; x < 4; x++)
8324 for(
int x = 0; x < 4; x++)
8341 AnsiString(LinkNumber) +
"," +
HeadCode);
8392 int DistanceToRedSignal = 0;
8393 float TimeToAct = 0;
8394 float MinsEarly = 0;
8395 TDateTime DepartureTime;
8396 TDateTime ArrivalTime;
8442 float CurrentStopTime;
8443 float LaterStopTime;
8444 float RecoverableTime;
8449 if(DistanceToRedSignal == -1)
8468 float TimeToSubtract, TotalStopTime;
8471 TimeToSubtract = RecoverableTime;
8515 if(CurrentStopTime > 0)
8517 TotalStopTime = CurrentStopTime + LaterStopTime;
8526 else if((MinsEarly > 0) && !
Stopped())
8528 TotalStopTime = LaterStopTime + MinsEarly;
8532 if(LaterStopTime == 0)
8534 TotalStopTime = CurrentStopTime;
8540 TotalStopTime = CurrentStopTime + LaterStopTime - TimeToSubtract;
8543 if(AvTrackSpeed < 30)
8547 int Speed = AvTrackSpeed;
8557 TimeToAct = TotalStopTime + DistanceToRedSignal * 3.6 / 60 / Speed;
8579 if((NextEntryPos == 0) || (NextEntryPos == 2))
8701 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8744 int IncrementalMinutes = 0;
8745 int IncrementalDigits = 0;
8753 throw Exception(
"Error - Repeat entry && less than two trains for Snt entry: " + TDEntry.
HeadCode);
8782 if(AVEntry0.
Command ==
"Snt-sh")
8787 int IncrementalMinutes = 0;
8788 int IncrementalDigits = 0;
8796 throw Exception(
"Error - Repeat entry && less than two trains for Snt-sh entry: " + TDEntry.
HeadCode);
8828 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8888 AnsiString Loc =
"";
8889 bool ElementFound =
false;
8894 ElementFound =
true;
8899 ElementFound =
true;
8904 ElementFound =
true;
8933 else if(AVEntryPtr->
Command ==
"Fer")
8935 bool CorrectExit =
false;
9043 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9058 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9073 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9084 bool TTrainController::AddTrain(
int Caller,
int RearPosition,
int FrontPosition, AnsiString HeadCode,
int StartSpeed,
int Mass,
double MaxRunningSpeed,
9085 double MaxBrakeRate,
double PowerAtRail, AnsiString ModeStr,
TTrainDataEntry *TrainDataEntryPtr,
int RepeatNumber,
int IncrementalMinutes,
9086 int IncrementalDigits,
int SignallerSpeed,
bool SignallerControl,
TActionEventType &EventType)
9088 LogEvent(AnsiString(Caller) +
",AddTrain," + AnsiString(RearPosition) +
"," + AnsiString(FrontPosition) +
"," + HeadCode +
"," + AnsiString(StartSpeed) +
9089 "," + AnsiString(Mass) +
"," + ModeStr);
9091 "," + HeadCode +
"," + AnsiString(StartSpeed) +
"," + AnsiString(Mass) +
"," + ModeStr +
"," + HeadCode);
9093 int RearExitPos = -1;
9095 for(
int x = 0; x < 4; x++)
9102 if(RearExitPos == -1)
9104 throw Exception(
"Error, RearExit == -1 in AddTrain");
9106 bool ReportFlag =
true;
9123 if(ModeStr ==
"Timetable")
9129 if(MaxRunningSpeed < 10)
9131 MaxRunningSpeed = 10;
9133 if(SignallerSpeed < 10)
9135 SignallerSpeed = 10;
9137 TTrain *NewTrain =
new TTrain(0, RearPosition, RearExitPos, HeadCode, StartSpeed, Mass, MaxRunningSpeed, MaxBrakeRate, PowerAtRail, TrainMode,
9138 TrainDataEntryPtr, RepeatNumber, IncrementalMinutes, IncrementalDigits, SignallerSpeed);
9143 if(SignallerControl)
9173 if(!SignallerControl)
9188 if(!SignallerControl)
9199 AnsiString Loc =
"";
9216 if(!SignallerControl)
9235 int RouteNumber = -1;
9236 bool SignalsSet =
false;
9243 int RouteStartPosition;
9247 if(FirstPair.first == RouteNumber)
9249 RouteStartPosition = FirstPair.second;
9251 else if(SecondPair.first == RouteNumber)
9253 RouteStartPosition = SecondPair.second;
9257 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 1st of 2 calls to SetAllRearwardsSignals in AddTrain");
9263 else if(RouteNumber > -1)
9283 int LinkedRouteNumber = -1;
9304 int RouteStartPosition;
9308 if(FirstPair.first == RouteNumber)
9310 RouteStartPosition = FirstPair.second;
9312 else if(SecondPair.first == RouteNumber)
9314 RouteStartPosition = SecondPair.second;
9318 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 2nd of 2 calls to SetAllRearwardsSignals in AddTrain");
9324 else if(RouteNumber > -1)
9344 int LinkedRouteNumber = -1;
9365 AnsiString(TrackVectorNumber));
9368 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9377 throw Exception(
"Error, VecPos not set in EntryPos");
9379 if(
TrainVectorAt(2, VecPos).LeadElement == TrackVectorNumber)
9384 else if(
TrainVectorAt(4, VecPos).MidElement == TrackVectorNumber)
9389 else if(
TrainVectorAt(6, VecPos).LagElement == TrackVectorNumber)
9403 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9411 throw Exception(
"Error - No Train identified in TrainVectorAtIdent with ID = " + AnsiString(TrainID));
9421 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9451 AnsiString RetStr =
"", PartStr =
"";
9459 if((Ptr->Command !=
"") && (Ptr->Command[1] ==
'S'))
9467 if(Ptr->SignallerControl)
9469 RetStr =
"Train under signaller control";
9474 if(Ptr->ArrivalTime == Ptr->DepartureTime)
9485 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime != TDateTime(-1)))
9489 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime == TDateTime(-1)))
9493 else if(Ptr->FormatType ==
PassTime)
9497 else if(Ptr->Command ==
"Fns")
9503 else if(Ptr->Command ==
"F-nshs")
9506 Ptr->NonRepeatingShuttleLinkHeadCode +
" at " + Ptr->LocationName;
9513 else if((Ptr->Command ==
"Fns-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
9520 else if((Ptr->Command ==
"Fns-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
9523 Ptr->NonRepeatingShuttleLinkHeadCode, +
" at " + Ptr->LocationName;
9526 else if((Ptr->Command ==
"Frh-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
9533 else if((Ptr->Command ==
"Frh-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
9535 PartStr =
"Terminate at " + Ptr->LocationName;
9537 else if(Ptr->Command ==
"Frh")
9539 PartStr =
"Terminate at " + Ptr->LocationName;
9541 else if(Ptr->Command ==
"Fer")
9543 AnsiString AllowedExits;
9547 else if(Ptr->Command ==
"Fjo")
9550 Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
9552 else if(Ptr->Command ==
"jbo")
9555 (50, Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
9557 else if(Ptr->Command ==
"fsp")
9562 else if(Ptr->Command ==
"rsp")
9567 else if(Ptr->Command ==
"cdt")
9573 RetStr = RetStr +
'\n' + PartStr;
9581 while(Ptr < TTDEPtr->ActionVector.end() && (Count < 33) && ((Ptr->Command ==
"") || ((Ptr->Command !=
"") && (Ptr->Command[1] !=
'F'))));
9594 + AnsiString(RptNum) +
",ControllerCheckNewServiceDepartureTime," + TDEPtr->
HeadCode);
9595 AnsiString DepTime =
"", EventTime =
"";
9596 bool CDTFlag =
false;
9600 if(AVI->Command ==
"cdt")
9605 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
9608 RetStr +=
"\nNew service splits at " + EventTime;
9612 if(AVI->Command ==
"jbo")
9615 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
9619 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
9624 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
9628 RetStr +=
"\nNew service departs at " + DepTime;
9788 ActiveTrackElementNameMapEntry.second = 0;
9794 std::ifstream TTBLFile(FileName, std::ios_base::binary);
9797 if(TTBLFile.is_open())
9799 char *TrainTimetableString =
new char[10000];
9801 bool EndOfFile =
false;
9804 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9806 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9813 delete[] TrainTimetableString;
9817 AnsiString OneLine(TrainTimetableString);
9818 bool FinalCallFalse =
false;
9819 while((Count == 0) && !
ProcessOneTimetableLine(5, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
9823 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9824 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9829 TimetableMessage(GiveMessages,
"Timetable invalid - unable to find a valid start time on its own line");
9831 delete[] TrainTimetableString;
9835 OneLine = AnsiString(TrainTimetableString);
9841 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9843 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9853 OneLine = AnsiString(TrainTimetableString);
9855 if(OneLine.Length() > 9999)
9857 TimetableMessage(GiveMessages,
"Timetable contains a line that is too long - 10,000 or more characters!");
9859 delete[] TrainTimetableString;
9863 bool FinalCallFalse =
false;
9864 if(!
ProcessOneTimetableLine(6, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
9868 delete[] TrainTimetableString;
9872 if(EndOfFile && (Count < 2))
9875 TimetableMessage(GiveMessages,
"Timetable has too few or no relevant entries - must have a start time on its own line and at least one train");
9877 delete[] TrainTimetableString;
9883 delete[] TrainTimetableString;
9888 TimetableMessage(GiveMessages,
"Failed to open timetable file, make sure it's not open in another application");
9899 bool CheckLocationsExistInRailway)
10024 AnsiString((
short)FinalCall) +
"," + AnsiString((
short)CheckLocationsExistInRailway));
10034 if(OneLine[1] !=
'*')
10036 int SCPos = OneLine.Pos(
';');
10047 bool AllCommas =
true;
10049 for(
int x = 1; x < OneLine.Length() + 1; x++)
10051 if(OneLine[x] !=
',')
10056 if(AllCommas || (OneLine ==
""))
10071 AnsiString First =
"", Second =
"", Third =
"", Fourth =
"";
10072 int RearStartOrRepeatMins = 0, FrontStartOrRepeatDigits = 0, NumberOfRepeats = 0;
10073 TDateTime EventTime(0), ArrivalTime(0), DepartureTime(0);
10074 TDateTime StartTime(0);
10076 bool Warning =
false;
10103 AnsiString TrainInfoStr =
"", HeadCode =
"", Description =
"";
10104 int StartSpeed = 0, MaxRunningSpeed = 0, Mass = 0;
10105 double MaxBrakeRate = 0;
10106 double PowerAtRail = 0;
10107 int SignallerSpeed = 0;
10108 if(OneLine[1] ==
'*')
10114 int Pos = OneLine.Pos(
',');
10117 int SubStringLength = 20;
10118 if(OneLine.Length() < 20)
10120 SubStringLength = OneLine.Length();
10122 TimetableMessage(GiveMessages,
"Error in timetable - entry incomplete: see '" + OneLine.SubString(1, SubStringLength) +
"'....");
10126 TrainInfoStr = OneLine.SubString(1, Pos - 1);
10127 if(!
SplitTrainInfo(0, TrainInfoStr, HeadCode, Description, StartSpeed, MaxRunningSpeed, Mass, MaxBrakeRate, PowerAtRail, SignallerSpeed,
10137 TempTrainDataEntry.
HeadCode = HeadCode;
10141 TempTrainDataEntry.
Mass = Mass;
10149 AnsiString NewRemainder = OneLine.SubString(Pos + 1, OneLine.Length() - Pos);
10152 while(NewRemainder[NewRemainder.Length()] ==
',')
10154 if(NewRemainder.Length() > 1)
10156 NewRemainder = NewRemainder.SubString(1, NewRemainder.Length() - 1);
10165 if(NewRemainder ==
"")
10167 TimetableMessage(GiveMessages,
"Error in timetable - no events following train: '" + OneLine +
"'");
10172 int CommaCount = 0;
10173 for(
int x = 1; x < NewRemainder.Length() + 1; x++)
10175 if(NewRemainder[x] ==
',')
10180 if(CommaCount == 0)
10182 if((NewRemainder.SubString(7, 3) !=
"Snt") || (NewRemainder[NewRemainder.Length()] !=
'S'))
10184 int SubStringLength = 20;
10185 if(OneLine.Length() < 20)
10187 SubStringLength = OneLine.Length();
10190 "Error in timetable - must have at least a start and a finish event for a train that is not started under signaller control - see line beginning: '" +
10191 OneLine.SubString(1, SubStringLength) +
"'....");
10196 AnsiString OneEntry =
"";
10201 bool FinishFlag =
false;
10202 for(
int x = 0; x < CommaCount + 1; x++)
10204 if((CommaCount == 0) || (x < CommaCount))
10209 if(CommaCount == 0)
10211 OneEntry = NewRemainder;
10216 Pos = NewRemainder.Pos(
',');
10217 OneEntry = NewRemainder.SubString(1, Pos - 1);
10218 NewRemainder = NewRemainder.SubString(Pos + 1, NewRemainder.Length() - Pos);
10224 RearStartOrRepeatMins = 0;
10225 FrontStartOrRepeatDigits = 0;
10226 NumberOfRepeats = 0;
10227 if(!
SplitEntry(0, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
10228 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
10230 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
10235 if(Warning && (Second ==
"Frh"))
10237 TimetableMessage(GiveMessages,
"Error in line - '" + OneEntry +
"': warnings cannot be given for 'Frh' events");
10241 if(Warning && (Second ==
"Fjo"))
10244 "': warnings cannot be given for 'Fjo' events, for a train join warning add a 'W' prefix to the 'jbo' event");
10250 if(SequenceType !=
Start)
10252 TimetableMessage(GiveMessages,
"Error in timetable - First event not a start event: '" + OneEntry +
"'");
10256 if((Second ==
"Snt") && (Fourth ==
'S') && (NewRemainder !=
""))
10258 if(NewRemainder[1] !=
'R')
10261 "Error in timetable - the only event that can follow a train created under signaller control is a repeat, see '" +
10267 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
10271 if((HeadCode ==
"") || (Description ==
"") || (MaxRunningSpeed == 0) || (Mass == 0) || (MaxBrakeRate == 0))
10274 TimetableMessage(GiveMessages,
"Error in timetable - train information incomplete before 'Snt' or 'Snt-sh' start event: '" +
10280 if((Second ==
"Sfs") || (Second ==
"Sns") || (Second ==
"Sns-sh") || (Second ==
"Sns-fsh"))
10285 TimetableMessage(GiveMessages,
"Error in timetable - headcode missing before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
10290 if((StartSpeed != 0) || (MaxRunningSpeed != 0) || (Mass != 0) || (MaxBrakeRate != 0) || (PowerAtRail != 0))
10293 "Error in timetable - information additional to a headcode & optional description given before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
10300 if(SequenceType ==
Finish)
10309 TDateTime TempTime;
10315 ActionVectorEntry.
Warning = Warning;
10331 ActionVectorEntry.
Command = Second;
10346 else if(FormatType ==
TimeCmd)
10352 ActionVectorEntry.
Command = Second;
10360 ActionVectorEntry.
Command = Second;
10361 ActionVectorEntry.
ExitList = ExitList;
10369 ActionVectorEntry.
Command = Second;
10383 ActionVectorEntry.
Command = Second;
10394 ActionVectorEntry.
Command = Second;
10404 ActionVectorEntry.
Command = Second;
10413 ActionVectorEntry.
Command = Second;
10422 ActionVectorEntry.
Command = Second;
10428 ActionVectorEntry.
Command = Second;
10430 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10435 OneEntry = NewRemainder;
10440 RearStartOrRepeatMins = 0;
10441 FrontStartOrRepeatDigits = 0;
10442 NumberOfRepeats = 0;
10443 if((FinishFlag) && (OneEntry[1] !=
'R'))
10446 TimetableMessage(GiveMessages,
"Error in timetable - Last event = '" + OneEntry +
"'. An earlier finish event has been found with something other than a repeat following it - only a repeat can follow a finish event.");
10450 if(OneEntry[1] !=
'R')
10452 if(!
SplitEntry(1, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
10453 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
10455 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
10459 if(SequenceType !=
Finish)
10461 TimetableMessage(GiveMessages,
"Error in timetable - last event should be a finish: '" + OneEntry +
"'");
10468 TDateTime TempTime;
10474 ActionVectorEntry.
Warning = Warning;
10481 ActionVectorEntry.
Command = Second;
10489 ActionVectorEntry.
Command = Second;
10498 ActionVectorEntry.
Command = Second;
10507 ActionVectorEntry.
Command = Second;
10517 ActionVectorEntry.
Command = Second;
10518 ActionVectorEntry.
ExitList = ExitList;
10522 ActionVectorEntry.
Command = Second;
10524 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10529 if(!
SplitRepeat(0, OneEntry, RearStartOrRepeatMins, FrontStartOrRepeatDigits, NumberOfRepeats, GiveMessages))
10545 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10564 if((HeadCode[HeadCode.Length() - 1] <
'0') || (HeadCode[HeadCode.Length() - 1] >
'9'))
10569 if((HeadCode[HeadCode.Length()] <
'0') || (HeadCode[HeadCode.Length()] >
'9'))
10584 if(TimeStr.Length() < 5)
10589 if((TimeStr[1] <
'0') || (TimeStr[1] >
'9'))
10594 if((TimeStr[2] <
'0') || (TimeStr[2] >
'9'))
10599 if(TimeStr[3] !=
':')
10604 if((TimeStr[4] <
'0') || (TimeStr[4] >
'5'))
10609 if((TimeStr[5] <
'0') || (TimeStr[5] >
'9'))
10614 while(TimeStr.Length() > 5)
10616 TimeStr = TimeStr.SubString(1, TimeStr.Length() - 1);
10618 double WholeHours = (AnsiString(TimeStr[1]) + AnsiString(TimeStr[2])).ToDouble();
10619 double FracHour = ((AnsiString(TimeStr[4]) + AnsiString(TimeStr[5])).ToDouble()) / 60.0;
10621 if((WholeHours + FracHour) >= 95.98334)
10626 Time = TDateTime((WholeHours + FracHour) / 24);
10633 bool TTrainController::SplitEntry(
int Caller, AnsiString OneEntry,
bool GiveMessages,
bool CheckLocationsExistInRailway, AnsiString &First, AnsiString &Second,
10634 AnsiString &Third, AnsiString &Fourth,
int &RearStartOrRepeatMins,
int &FrontStartOrRepeatDigits,
TTimetableFormatType &FormatType,
10643 TDateTime TempTime;
10645 if(OneEntry.Length() > 0)
10647 if(OneEntry[1] ==
'W')
10650 OneEntry = OneEntry.SubString(2, OneEntry.Length() - 1);
10654 if(OneEntry ==
"Frh")
10664 if(OneEntry.Length() < 7)
10669 int Pos = OneEntry.Pos(
';');
10677 First = OneEntry.SubString(1, 5);
10683 AnsiString Remainder = OneEntry.SubString(Pos + 1, OneEntry.Length() - Pos);
10685 if((Remainder[1] >=
'0') && (Remainder[1] <=
'9'))
10688 if(Remainder.Length() < 7)
10693 Pos = Remainder.Pos(
';');
10700 Second = Remainder.SubString(1, 5);
10706 Third = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10719 Pos = Remainder.Pos(
';');
10722 Second = Remainder;
10723 if(Second ==
"cdt")
10748 if((Pos != 4) && (Pos != 7) && (Pos != 8))
10754 Second = Remainder.SubString(1, Pos - 1);
10756 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10758 Pos = Remainder.Pos(
';');
10765 Third = Remainder.SubString(1, Pos - 1);
10766 Fourth = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10768 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
10771 int SpacePos = Third.Pos(
' ');
10777 AnsiString RearStartStr = Third.SubString(1, SpacePos - 1);
10778 AnsiString FrontStartStr = Third.SubString(SpacePos + 1, Third.Length() - SpacePos);
10780 if(CheckLocationsExistInRailway)
10790 if(Second ==
"Snt")
10793 SequenceType =
Start;
10802 SequenceType =
Start;
10813 if(Second ==
"Sns-sh")
10817 SequenceType =
Start;
10832 if(Second ==
"F-nshs")
10846 if(Second ==
"Sns-fsh")
10850 SequenceType =
Start;
10860 if(Second ==
"Fns-sh")
10880 if(Second ==
"pas")
10895 if(Second ==
"Fer")
10902 if(CheckLocationsExistInRailway)
10914 if((Second !=
"Fns") && (Second !=
"Fjo") && (Second !=
"jbo") && (Second !=
"fsp") && (Second !=
"rsp") && (Second !=
"Sfs") && (Second !=
"Sns") &&
10915 (Second !=
"Frh-sh"))
10927 if(Second ==
"Frh-sh")
10935 if((Second ==
"Fns") || (Second ==
"Fjo") || (Second ==
"Frh-sh"))
10939 if((Second ==
"jbo") || (Second ==
"fsp") || (Second ==
"rsp"))
10943 if((Second ==
"Sfs") || (Second ==
"Sns"))
10945 SequenceType =
Start;
10963 if((LocStr[1] >=
'0') && (LocStr[1] <=
'9'))
10968 for(
int x = 1; x < LocStr.Length() + 1; x++)
10970 if(LocStr[x] <
' ')
10975 if(LocStr[x] >
'z')
10982 if(CheckLocationsExistInRailway)
10987 "' appears in the timetable but is not a valid name. To be valid the name must be a stopping location and apply to one or more platforms " +
10988 "(not concourses on their own), or to track at a blue non-station named location. BUT NOTE THAT trains can't stop at continuations so a name " +
10989 "that includes a continuation will not be valid.");
11007 if((HeadCode.Length() < 4) || (HeadCode.Length() > 8))
11010 "', length must be between 4 and 8 characters, and last 4 must be a legitimate headcode. This error can also be caused by omitting a service reference after Snt-sh, Sns-sh, Fns-sh or Frh-sh");
11015 for(
int x = 1; x < (HeadCode.Length() + 1); x++)
11017 if((HeadCode[x] <
' ') || (HeadCode[x] >
'~'))
11019 TimetableMessage(GiveMessages,
"Non-printable character in headcode '" + HeadCode +
"'");
11025 for(
int x = 3; x >= 0; x--)
11027 if(((HeadCode[HeadCode.Length() - x] <
'A') || (HeadCode[HeadCode.Length() - x] >
'Z')) && ((HeadCode[HeadCode.Length() - x] <
'a') ||
11028 (HeadCode[HeadCode.Length() - x] >
'z')) && ((HeadCode[HeadCode.Length() - x] <
'0') || (HeadCode[HeadCode.Length() - x] >
'9')))
11030 TimetableMessage(GiveMessages,
"Headcode error in '" + HeadCode +
"', headcode must consist of letters and digits only");
11046 AnsiString CurrentID =
"";
11048 if(IDSet.Length() == 0)
11050 TimetableMessage(GiveMessages,
"Must have at least one exit element ID following 'Fer'");
11054 for(
int x = 1; x <= IDSet.Length(); x++)
11057 if(((C <
'0') || (C >
'9')) && (C !=
' ') && (C !=
'N') && (C !=
'-'))
11059 TimetableMessage(GiveMessages,
"Illegal character in the set of element IDs following 'Fer' in '" + IDSet +
"'");
11064 int Pos = IDSet.Pos(
' ');
11075 CurrentID = IDSet.SubString(1, Pos - 1);
11076 IDSet = IDSet.SubString(Pos + 1, IDSet.Length() - Pos);
11088 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' is not an exit");
11095 if(!ExitList.empty())
11099 if(*ELIT == VecPos)
11101 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' duplicates an earlier element");
11108 ExitList.push_back(VecPos);
11118 Pos = IDSet.Pos(
' ');
11125 int &Mass,
double &MaxBrakeRate,
double &PowerAtRail,
int &SignallerSpeed,
bool GiveMessages)
11132 AnsiString Remainder =
"";
11133 int SemiColonCount = 0;
11135 for(
int x = 1; x < TrainInfoStr.Length() + 1; x++)
11137 if(TrainInfoStr[x] ==
';')
11142 if((SemiColonCount != 6) && (SemiColonCount != 7) && (SemiColonCount != 1) && (SemiColonCount != 0))
11144 TimetableMessage(GiveMessages,
"Error in train information in '" + TrainInfoStr +
11145 "'. Should be headcode + optional description for a continuing service;" +
11146 " or headcode, description, start speed, max running speed, mass, brake force, power (and optional signaller max. speed) for a new service");
11150 if(SemiColonCount == 0)
11152 HeadCode = TrainInfoStr;
11161 if(SemiColonCount == 1)
11163 Pos = TrainInfoStr.Pos(
';');
11164 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
11165 Description = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
11171 if(Description ==
"")
11173 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
11177 if(Description.Length() > 60)
11179 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
11183 for(
int x = 1; x < Description.Length() + 1; x++)
11185 if((Description[x] <
' ') || (Description[x] >
'~'))
11187 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
11196 Pos = TrainInfoStr.Pos(
';');
11197 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
11198 Remainder = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
11204 Pos = Remainder.Pos(
';');
11205 Description = Remainder.SubString(1, Pos - 1);
11206 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11207 if(Description ==
"")
11209 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
11213 if(Description.Length() > 60)
11215 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
11219 for(
int x = 1; x < Description.Length() + 1; x++)
11221 if((Description[x] <
' ') || (Description[x] > 126))
11223 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
11228 Pos = Remainder.Pos(
';');
11229 AnsiString StartSpeedStr = Remainder.SubString(1, Pos - 1);
11231 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11232 if(StartSpeedStr ==
"")
11234 TimetableMessage(GiveMessages,
"Train starting speed missing in '" + TrainInfoStr +
"'");
11238 for(
int x = 1; x < StartSpeedStr.Length() + 1; x++)
11240 if((StartSpeedStr[x] <
'0') || (StartSpeedStr[x] >
'9'))
11242 TimetableMessage(GiveMessages,
"Train start speed contains invalid characters in '" + TrainInfoStr +
"'");
11247 StartSpeed = StartSpeedStr.ToInt();
11253 TimetableMessage(GiveMessages,
"Train starting speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11257 Pos = Remainder.Pos(
';');
11258 AnsiString MaxRunningSpeedStr = Remainder.SubString(1, Pos - 1);
11260 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11261 if(MaxRunningSpeedStr ==
"")
11263 TimetableMessage(GiveMessages,
"Train maximum running speed missing in '" + TrainInfoStr +
"'");
11267 for(
int x = 1; x < MaxRunningSpeedStr.Length() + 1; x++)
11269 if((MaxRunningSpeedStr[x] <
'0') || (MaxRunningSpeedStr[x] >
'9'))
11271 TimetableMessage(GiveMessages,
"Train maximum running speed contains invalid characters in '" + TrainInfoStr +
"'");
11276 MaxRunningSpeed = MaxRunningSpeedStr.ToInt();
11282 TimetableMessage(GiveMessages,
"Train maximum running speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11286 if(MaxRunningSpeed < 10)
11289 MaxRunningSpeed = 10;
11292 TimetableMessage(GiveMessages,
"Train maximum running speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
11296 Pos = Remainder.Pos(
';');
11297 AnsiString MassStr = Remainder.SubString(1, Pos - 1);
11299 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11302 TimetableMessage(GiveMessages,
"Train mass missing in '" + TrainInfoStr +
"'");
11306 for(
int x = 1; x < MassStr.Length() + 1; x++)
11308 if((MassStr[x] <
'0') || (MassStr[x] >
'9'))
11310 TimetableMessage(GiveMessages,
"Train mass contains invalid characters in '" + TrainInfoStr +
"'");
11315 Mass = MassStr.ToInt() * 1000;
11321 TimetableMessage(GiveMessages,
"Train mass > 10,000 tonnes in '" + TrainInfoStr +
"'. Setting it to 10,000 tonnes");
11327 TimetableMessage(GiveMessages,
"Train mass zero in '" + TrainInfoStr +
"'");
11331 Pos = Remainder.Pos(
';');
11332 AnsiString MaxBrakeForceStr = Remainder.SubString(1, Pos - 1);
11334 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11335 if(MaxBrakeForceStr ==
"")
11337 TimetableMessage(GiveMessages,
"Train braking force missing in '" + TrainInfoStr +
"'");
11341 for(
int x = 1; x < (MaxBrakeForceStr.Length() + 1); x++)
11343 if((MaxBrakeForceStr[x] !=
'.') && ((MaxBrakeForceStr[x] <
'0') || (MaxBrakeForceStr[x] >
'9')))
11345 TimetableMessage(GiveMessages,
"Train braking force contains invalid characters in '" + TrainInfoStr +
"'");
11350 double MaxBrakeForce = MaxBrakeForceStr.ToDouble() * 1000;
11353 if((MaxBrakeForce / Mass) > 1)
11355 MaxBrakeForce = Mass;
11358 TimetableMessage(GiveMessages,
"Train braking force too high in '" + TrainInfoStr +
"'. Setting it to the same as the train mass");
11362 if((MaxBrakeForce / Mass) < 0.01)
11364 MaxBrakeForce = Mass * 0.01;
11367 TimetableMessage(GiveMessages,
"Train braking force too low in '" + TrainInfoStr +
"'. Setting it to 1% of the train mass");
11372 MaxBrakeRate = MaxBrakeForce / Mass * 9.81;
11374 AnsiString GrossPowerStr =
"", SignallerSpeedStr =
"";
11376 if(SemiColonCount == 6)
11378 GrossPowerStr = Remainder;
11379 SignallerSpeedStr =
"30";
11383 Pos = Remainder.Pos(
';');
11384 GrossPowerStr = Remainder.SubString(1, Pos - 1);
11385 SignallerSpeedStr = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11388 if(GrossPowerStr ==
"")
11390 TimetableMessage(GiveMessages,
"Train power missing in '" + TrainInfoStr +
"'");
11394 for(
int x = 1; x < GrossPowerStr.Length() + 1; x++)
11396 if((GrossPowerStr[x] <
'0') || (GrossPowerStr[x] >
'9'))
11398 TimetableMessage(GiveMessages,
"Train power contains invalid characters in '" + TrainInfoStr +
"'");
11404 double GrossPower = GrossPowerStr.ToInt() * 1000;
11411 TimetableMessage(GiveMessages,
"Train power > 100,000kW in '" + TrainInfoStr +
"'. Setting it to 100,000kW");
11415 else if(GrossPower == 0)
11420 else if((GrossPower > 0) && (GrossPower < 10000))
11423 GrossPower = 10000;
11425 PowerAtRail = GrossPower * 0.8;
11429 if(SignallerSpeedStr ==
"")
11431 TimetableMessage(GiveMessages,
"Signaller speed not set in '" + TrainInfoStr +
"', either set a value or remove the extra semicolon");
11435 for(
int x = 1; x < SignallerSpeedStr.Length() + 1; x++)
11437 if((SignallerSpeedStr[x] <
'0') || (SignallerSpeedStr[x] >
'9'))
11439 TimetableMessage(GiveMessages,
"Signaller speed contains invalid characters in '" + TrainInfoStr +
"'");
11444 SignallerSpeed = SignallerSpeedStr.ToInt();
11450 TimetableMessage(GiveMessages,
"Signaller speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11454 if(SignallerSpeed < 10)
11457 SignallerSpeed = 10;
11460 TimetableMessage(GiveMessages,
"Signaller speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
11478 if(OneEntry.Length() < 7)
11480 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11484 int SemiColonCount = 0;
11486 for(
int x = 1; x < OneEntry.Length() + 1; x++)
11488 if(OneEntry[x] ==
';')
11493 if(SemiColonCount != 3)
11495 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11499 if((OneEntry[1] !=
'R') || (OneEntry[2] !=
';'))
11501 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11505 AnsiString Remainder = OneEntry.SubString(3, OneEntry.Length() - 2);
11510 Pos = Remainder.Pos(
';');
11511 AnsiString MinutesStr = Remainder.SubString(1, Pos - 1);
11513 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11514 if(MinutesStr ==
"")
11516 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute increment segment missing");
11520 if(MinutesStr.Length() > 3)
11523 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute value too high, maximum value is 999");
11527 for(
int x = 1; x < MinutesStr.Length() + 1; x++)
11529 if((MinutesStr[x] <
'0') || (MinutesStr[x] >
'9'))
11531 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in minute increment segment");
11536 RearStartOrRepeatMins = MinutesStr.ToInt();
11537 if(RearStartOrRepeatMins == 0)
11539 TimetableMessage(GiveMessages,
"Repeat minute increment is zero in: '" + OneEntry +
"' - can't have a zero value");
11543 Pos = Remainder.Pos(
';');
11544 AnsiString DigitsStr = Remainder.SubString(1, Pos - 1);
11546 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11547 if(DigitsStr ==
"")
11549 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - headcode increment segment missing");
11553 for(
int x = 1; x < DigitsStr.Length() + 1; x++)
11555 if((DigitsStr[x] <
'0') || (DigitsStr[x] >
'9'))
11557 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in headcode increment segment");
11562 if(DigitsStr.Length() > 2)
11564 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - maximum number of digits for headcode increment is 2");
11568 FrontStartOrRepeatDigits = DigitsStr.ToInt();
11582 "' - a repeating service with incrementing digits must have digits as its last two headcode characters");
11586 AnsiString NumberStr = Remainder;
11588 if(NumberStr ==
"")
11590 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - number of repeats missing");
11594 if(NumberStr.Length() > 4)
11597 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - repeat value too high, no timetabled event can exceed 95 hours & 59 minutes");
11601 for(
int x = 1; x < NumberStr.Length() + 1; x++)
11603 if((NumberStr[x] <
'0') || (NumberStr[x] >
'9'))
11606 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in number of repeats");
11611 NumberOfRepeats = NumberStr.ToInt();
11612 if(NumberOfRepeats == 0)
11614 TimetableMessage(GiveMessages,
"Number of repeats is zero in: '" + OneEntry +
"' - if no repeats are needed the repeat should be omitted");
11770 SecondPassMessage(GiveMessages,
"Error in timetable - there appear to be no train services in the timetable, it must contain at least one");
11789 TwoLocationFlag =
false;
11795 SecondPassMessage(GiveMessages,
"Error in timetable - the following service has no listed events, there must be at least one: " + TDEntry.
HeadCode);
11809 SecondPassMessage(GiveMessages,
"Error in timetable - service must have a start event and at least one other for: " + TDEntry.
HeadCode);
11825 "Error in timetable - a signaller control service can have no more than one item (a repeat) after the start event, see: " +
11837 "Error in timetable - a signaller control service cannot have any other than a repeat after the start event, see: " + TDEntry.
HeadCode);
11864 SecondPassMessage(GiveMessages,
"Error in timetable - finish events Fns-sh and Frh-sh not permitted immediately after an Snt entry for: " +
11875 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11880 SecondPassMessage(GiveMessages,
"Error in timetable - a start event is present that is not the first event for: " + TDEntry.
HeadCode);
11890 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11895 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat is present that is not the last item for: " + TDEntry.
HeadCode);
11905 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11916 SecondPassMessage(GiveMessages,
"Error in timetable - the last item must be either a finish event or a repeat for: " + TDEntry.
HeadCode);
11926 SecondPassMessage(GiveMessages,
"Error in timetable - the last event before the repeat must be a finish for: " + TDEntry.
HeadCode);
11938 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11945 SecondPassMessage(GiveMessages,
"Error in timetable - a finish event must be either the last or last but one for: " + TDEntry.
HeadCode);
11954 SecondPassMessage(GiveMessages,
"Error in timetable - the only event that can follow a finish event is a repeat for: " +
11974 if((AVEntry0.
Command ==
"Snt") || (AVEntry0.
Command ==
"Snt-sh"))
11976 AnsiString LocationName =
"";
11992 SecondPassMessage(GiveMessages,
"Error in timetable - stopped 'Snt' or 'Snt-sh' followed by an illegal event for: " +
11993 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
12002 SecondPassMessage(GiveMessages,
"Error in timetable - 'Snt' or 'Snt-sh' event at stop location but start speed not zero for: " +
12011 if(AVEntry0.
Command ==
"Snt-sh")
12025 SecondPassMessage(GiveMessages,
"Error in timetable - unlocated 'Snt' not followed by 'Fer', 'pas' or an arrival for: " +
12041 SecondPassMessage(GiveMessages,
"Error in timetable - 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' followed by an illegal event for: " +
12042 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
12053 bool FoundFlag =
false;
12059 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12071 SecondPassMessage(GiveMessages,
"Error in timetable - no location departure following an 'Sfs', 'Sns', 'Sns-sh'or 'Sns-fsh' event for: " +
12084 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12093 ": an event should have had a location name associated with it but it could not be found");
12099 for(
unsigned int z = y + 1; z <
TrainDataVector.at(x).ActionVector.size(); z++)
12121 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12131 SecondPassMessage(GiveMessages,
"Error in timetable - only a repeat can follow a finish entry for: " + TDEntry.
HeadCode);
12138 if(AVEntry.
Command ==
"F-nshs")
12143 SecondPassMessage(GiveMessages,
"Error in timetable - F-nshs (shuttle link) must be the last event for: " + TDEntry.
HeadCode);
12171 SecondPassMessage(GiveMessages,
"Error in timetable - a jbo event is followed by an illegal event for: " + TDEntry.
HeadCode +
12172 ". The event isn't valid for a stationary train.");
12182 SecondPassMessage(GiveMessages,
"Error in timetable - a train split can't be the last event for: " + TDEntry.
HeadCode);
12190 SecondPassMessage(GiveMessages,
"Error in timetable - a train split is followed by an illegal event for: " + TDEntry.
HeadCode +
12191 ". The event isn't valid for a stationary train.");
12209 SecondPassMessage(GiveMessages,
"Error in timetable - a 'cdt' is followed by an illegal event for: " + TDEntry.
HeadCode +
12210 ". The event isn't valid for a stationary train.");
12220 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure can't be the last event for: " + TDEntry.
HeadCode);
12228 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure is followed by an illegal event for: " +
12229 TDEntry.
HeadCode +
". The event isn't valid for a moving train.");
12247 SecondPassMessage(GiveMessages,
"Error in timetable - a pass time is followed by an illegal event for: " + TDEntry.
HeadCode +
12248 ". The event isn't valid for a moving train.");
12270 bool LastEntryIsAnArrival =
false;
12277 LastEntryIsAnArrival =
false;
12278 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12285 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
12287 if(LastEntryIsAnArrival)
12291 LastEntryIsAnArrival =
false;
12297 LastEntryIsAnArrival =
true;
12304 LastEntryIsAnArrival =
true;
12305 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12312 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
12314 if(LastEntryIsAnArrival)
12318 LastEntryIsAnArrival =
false;
12324 LastEntryIsAnArrival =
true;
12334 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12342 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival can't be the last event for: " + TDEntry.
HeadCode);
12350 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival is followed by an illegal event for: " + TDEntry.
HeadCode +
12351 ". The event isn't valid for a stationary train.");
12362 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure can't be the last event for: " + TDEntry.
HeadCode);
12370 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure is followed by an illegal event for: " + TDEntry.
HeadCode +
12371 ". The event isn't valid for a moving train.");
12385 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12392 throw Exception(
"Timetable error, TimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
12396 throw Exception(
"Timetable error, TimeLoc entry has neither arrival nor departure time set for " + TDEntry.
HeadCode);
12403 throw Exception(
"Timetable error, TimeTimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
12407 throw Exception(
"Timetable error, TimeTimeLoc entry has either arrival or departure time not set for " + TDEntry.
HeadCode);
12416 throw Exception(
"Timetable error, Cmd or PassTime entry has EventTime not set for " + TDEntry.
HeadCode);
12420 throw Exception(
"Timetable error, Cmd or PassTime entry has either arrival or departure time set for " + TDEntry.
HeadCode);
12427 throw Exception(
"Timetable error, Repeat entry has a time set for " + TDEntry.
HeadCode);
12438 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12453 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has a later arrival than departure time for: " +
12461 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has too early an arrival time for: " +
12476 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
12488 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
12500 SecondPassMessage(GiveMessages,
"Error in timetable - a train event has a time that is set too early for: " + TDEntry.
HeadCode +
12501 ", may be before timetable start time");
12512 AnsiString LastLocationName =
"";
12516 bool LastEntryIsAnArrival =
false;
12521 LastEntryIsAnArrival =
false;
12522 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
12523 if(LastLocationName !=
"")
12525 throw Exception(
"Timetable error, moving Snt entry has LocationName set for " + TDEntry.
HeadCode);
12527 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size();
12540 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12552 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12565 TwoLocationFlag =
true;
12572 LastEntryIsAnArrival =
false;
12576 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
12579 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
12584 else if(!LastEntryIsAnArrival && (AVEntry.
LocationName == LastLocationName))
12587 "Error in timetable - a location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode);
12593 LastEntryIsAnArrival = !LastEntryIsAnArrival;
12599 LastEntryIsAnArrival =
true;
12600 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
12601 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12613 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12625 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12638 TwoLocationFlag =
true;
12643 LastEntryIsAnArrival =
false;
12647 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
12650 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
12658 "A location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode +
". Please correct if this is an error.\n\nThis warning will not be shown again.");
12665 LastEntryIsAnArrival = !LastEntryIsAnArrival;
12673 AnsiString LocationNameToBeChecked =
"";
12678 unsigned int y = 0;
12693 LocationNameToBeChecked = TDEntry.
ActionVector.at(y).LocationName;
12694 for(
unsigned int z = y; z < TDEntry.
ActionVector.size(); z++)
12712 for(
unsigned int a = z; a < TDEntry.
ActionVector.size(); a++)
12721 TwoLocationFlag =
true;
12737 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12742 throw Exception(
"Error, non- 'Snt', 'Fer' or Repeat entry doesn't have a location name set for " + TDEntry.
HeadCode);
12744 AnsiString LocName =
"";
12750 throw Exception(
"Error, 'Snt' entry at a stop location doesn't have a location name set for " + TDEntry.
HeadCode);
12757 throw Exception(
"Error, 'Snt' unlocated entry has a location name set for " + TDEntry.
HeadCode);
12780 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12805 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12827 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12849 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12868 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12871 if((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh"))
12886 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12891 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has FormatType unset for: " + TDEntry.
HeadCode);
12895 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has SequenceType unset for: " + TDEntry.
HeadCode);
12899 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has LocationType unset for: " + TDEntry.
HeadCode);
12903 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has ShuttleLinkType unset for: " + TDEntry.
HeadCode);
12942 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12944 AnsiString LocName =
TrainDataVector.at(x).ActionVector.at(y).LocationName;
12950 SecondPassMessage(GiveMessages,
"Error in timetable - continuation names (" + LocName +
") must not be included, see service " + HC);
12963 int IncMinutes = 0;
12973 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12979 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat time exceeds 95h 59m, see service " + HC);
12985 if((
double)
TrainDataVector.at(x).ActionVector.at(y).ArrivalTime > -1)
12990 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
12996 if((
double)
TrainDataVector.at(x).ActionVector.at(y).DepartureTime > -1)
13001 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
13014 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13040 (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"F-nshs"));
13048 if(HeadCode.Length() > 4)
13050 HeadCode = HeadCode.SubString(HeadCode.Length() - 3, 4);
13061 int ForwardCount = 0;
13062 int ReverseCount = 0;
13064 if(MainHeadCode == SecondHeadCode)
13066 SecondPassMessage(GiveMessages,
"Error in timetable - Service " + MainHeadCode +
" has an event that references itself");
13075 if(TDEntry.
HeadCode == MainHeadCode)
13077 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13092 if(ForwardCount == 0)
13095 throw Exception(
"Error, ForwardCount == 0 in CheckForDuplicateCrossReferences after called with found values");
13097 if(ForwardCount > 2)
13100 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + SecondHeadCode +
" from a train whose headcode is " +
13101 MainHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
13110 if(TDEntry.
HeadCode == SecondHeadCode)
13112 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13127 if(ReverseCount == 0)
13129 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + SecondHeadCode);
13134 if(ReverseCount > 2)
13137 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + MainHeadCode +
" from a train whose headcode is " +
13138 SecondHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
13143 if(ForwardCount != ReverseCount)
13145 SecondPassMessage(GiveMessages,
"Error in timetable - " + MainHeadCode +
" has a different number of references to " + SecondHeadCode +
13146 " than the other way round");
13177 int ForwardCount = 0;
13178 int ReverseCount = 0;
13179 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
13188 if(TDEntry.
HeadCode == MainHeadCode)
13190 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13193 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
13198 ForwardEntryPtr = &AVEntry;
13200 ForwardTDVectorNumber = x;
13203 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") ||
13204 (AVEntry.
Command ==
"Frh-sh")))
13209 ForwardEntryPtr = &AVEntry;
13211 ForwardTDVectorNumber = x;
13217 if(ForwardCount == 0)
13220 throw Exception(
"Error, ForwardCount == 0 in CheckCrossReferencesAndSetData after called with found values");
13222 if(ForwardCount > 1)
13224 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + OtherHeadCode +
" from a train whose headcode is " +
13234 if(TDEntry.
HeadCode == OtherHeadCode)
13236 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13239 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
13245 ReverseEntryPtr = &AVEntry;
13246 ReverseTDVectorNumber = x;
13249 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"Frh-sh")))
13255 ReverseEntryPtr = &AVEntry;
13256 ReverseTDVectorNumber = x;
13263 if(ReverseCount == 0)
13265 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + OtherHeadCode);
13270 if(ReverseCount > 1)
13272 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
13279 bool ForwardShuttleStart = ((ForwardEntryPtr->Command ==
"Sns-sh") || (ForwardEntryPtr->Command ==
"Snt-sh"));
13280 bool ForwardShuttleFinish = ((ForwardEntryPtr->Command ==
"Fns-sh") || (ForwardEntryPtr->Command ==
"Frh-sh"));
13281 bool ReverseShuttleStart = ((ReverseEntryPtr->
Command ==
"Sns-sh") || (ReverseEntryPtr->
Command ==
"Snt-sh"));
13282 bool ReverseShuttleFinish = ((ReverseEntryPtr->
Command ==
"Fns-sh") || (ReverseEntryPtr->
Command ==
"Frh-sh"));
13286 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat");
13293 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + OtherHeadCode +
" does not have a repeat");
13298 if(ForwardEntryPtr->LocationName ==
"")
13300 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
13301 ". One or other service does not have a location set");
13308 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
13309 ". One or other service does not have a location set");
13314 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
13316 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
13317 " is at a different location to the referencing train " + MainHeadCode);
13325 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
13327 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
13328 " has a different event time to the referencing train " + MainHeadCode);
13336 if(ForwardShuttleStart && ReverseShuttleFinish)
13341 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle service " + MainHeadCode +
13342 " first repeat restart time not consistent with finish service " + OtherHeadCode);
13348 if((ReverseEntryPtr->
Command ==
"Sfs") || (ReverseEntryPtr->
Command ==
"Sns"))
13351 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13353 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Sfs' or 'Sns' event (" + OtherHeadCode +
13354 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13360 if(ReverseEntryPtr->
Command ==
"Fjo")
13363 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13365 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fjo' event (" + OtherHeadCode +
13366 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13372 if(ReverseEntryPtr->
Command ==
"Fns")
13375 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13377 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fns' event (" + OtherHeadCode +
13378 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13384 if(ForwardEntryPtr->Command ==
"Sfs")
13386 if((ReverseEntryPtr->
Command !=
"fsp") && (ReverseEntryPtr->
Command !=
"rsp"))
13389 "Error in timetable - unable to find a corresponding split train event for the train that starts from a split whose headcode is " +
13396 if((ForwardEntryPtr->Command ==
"fsp") || (ForwardEntryPtr->Command ==
"rsp"))
13398 if(ReverseEntryPtr->
Command !=
"Sfs")
13400 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sfs' event for the train split whose headcode is " +
13410 SecondPassMessage(GiveMessages,
"Error in timetable - can't find timetabled location '" + ForwardEntryPtr->LocationName +
"' in railway - perhaps there are concourses without platforms?");
13417 SecondPassMessage(GiveMessages,
"Error in timetable - can't find any named location elements at '" + ForwardEntryPtr->LocationName +
"' - perhaps there are concourses without platforms?");
13424 SecondPassMessage(GiveMessages,
"Error in timetable - location too short to split a train at " + ForwardEntryPtr->LocationName);
13429 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13440 if(ForwardEntryPtr->Command ==
"Sns")
13442 if(ReverseEntryPtr->
Command !=
"Fns")
13444 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fns' event for the 'Sns' train whose headcode is " +
13445 MainHeadCode +
" and is formed from a service with headcode " + OtherHeadCode);
13451 if(ForwardEntryPtr->Command ==
"Fns")
13453 if(ReverseEntryPtr->
Command !=
"Sns")
13455 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns' event for the train whose headcode is " + MainHeadCode +
13456 " and forms a new service with headcode " + OtherHeadCode);
13463 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13474 if(ForwardEntryPtr->Command ==
"jbo")
13476 if(ReverseEntryPtr->
Command !=
"Fjo")
13478 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fjo' event for the train whose headcode is " + MainHeadCode +
13479 " and is joined by a train with headcode " + OtherHeadCode);
13485 if(ForwardEntryPtr->Command ==
"Fjo")
13487 if(ReverseEntryPtr->
Command !=
"jbo")
13489 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'jbo' event for the train whose headcode is " + MainHeadCode +
13490 " and joins a train with headcode " + OtherHeadCode);
13497 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13507 if(ForwardShuttleStart)
13510 if(!ReverseShuttleFinish)
13513 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + MainHeadCode +
13514 " from train whose headcode is " + OtherHeadCode +
", has to be Fns-sh, Frh-sh");
13520 if(ReverseShuttleStart)
13523 if(!ForwardShuttleFinish)
13526 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + OtherHeadCode +
13527 " from train whose headcode is " + MainHeadCode +
", has to be Fns-sh, Frh-sh");
13534 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13546 bool MainRepeat =
false, OtherRepeat =
false;
13556 OtherRepeat =
true;
13559 if((MainRepeat && !OtherRepeat) || (!MainRepeat && OtherRepeat))
13561 SecondPassMessage(GiveMessages,
"Error in timetable - only one repeat is provided for the train whose headcode is " + MainHeadCode +
13562 " and the associated train with headcode " + OtherHeadCode);
13567 if(MainRepeat && OtherRepeat)
13573 SecondPassMessage(GiveMessages,
"Error in timetable - repeat items don't correspond for the train whose headcode is " + MainHeadCode +
13574 " and the associated train with headcode " + OtherHeadCode);
13596 while(Input[1] ==
' ')
13598 if(Input.Length() > 1)
13600 Input = Input.SubString(2, Input.Length() - 1);
13614 while(Input[Input.Length()] ==
' ')
13616 if(Input.Length() > 1)
13618 Input = Input.SubString(1, Input.Length() - 1);
13628 AnsiString Output =
"";
13629 bool DelimiterFound =
false;
13631 for(
int x = 1; x < Input.Length() + 1; x++)
13635 if(Input[x] ==
' ')
13640 if((Input[x] !=
',') && (Input[x] !=
';'))
13642 DelimiterFound =
false;
13643 Output = Output + Input[x];
13647 DelimiterFound =
true;
13648 Output = Output + Input[x];
13660 DelimiterFound =
false;
13661 for(
int x = Input.Length(); x > 0; x--)
13665 if(Input[x] ==
' ')
13670 if((Input[x] !=
',') && (Input[x] !=
';'))
13672 DelimiterFound =
false;
13673 Output = AnsiString(Input[x]) + Output;
13677 DelimiterFound =
true;
13678 Output = AnsiString(Input[x]) + Output;
13698 if((AVEntry0.
Command !=
"Snt") && (AVEntry0.
Command !=
"Snt-sh"))
13700 throw Exception(
"Error, first entry not 'Snt' or 'Snt-sh' in IsSNTEntryLocated");
13712 LocationName = LocRear;
13716 LocationName = LocFront;
13718 if(LocationName ==
"")
13744 AnsiString TimeLocLocationName;
13745 bool FoundFlag =
false;
13747 for(
unsigned int y = 0; y < TDEntry.
ActionVector.size(); y++)
13762 if(TimeLocLocationName == LocationName)
13779 int RearPosition = 0, FrontPosition = 0, RearExitPos = 0;
13782 if(RearPosition < 0)
13789 if(FrontPosition < 0)
13800 for(
int x = 0; x < 4; x++)
13802 if(RearTrackElement.
Conn[x] == FrontPosition)
13817 TimetableMessage(GiveMessages,
"Front of train attempting to start on a continuation at: " + FrontElementStr);
13824 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + FrontElementStr);
13830 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + RearElementStr);
13835 if((RearType ==
Points) && (RearExitPos == 3))
13837 TimetableMessage(GiveMessages,
"Front of train attempting to start on element connected to diverging points at: " + RearElementStr);
13843 TimetableMessage(GiveMessages,
"Rear of train attempting to start on element connected to diverging points at: " + FrontElementStr);
13858 AnsiString(RearExitPos));
13869 int FrontPosition = RearTrackElement.
Conn[RearExitPos];
13871 int FrontEntryPos = RearTrackElement.
ConnLinkPos[RearExitPos];
13874 AnsiString RearName, FrontName;
13890 FrontName = FrontTrackElement.
ElementID;
13893 int LockedVectorNumber;
14063 "," + AnsiString(IncDigits));
14066 throw Exception(
"Error, last 2 characters not both digits and IncDigits > 0 in GetRepeatHeadCode");
14071 return(BaseHeadCode);
14073 int BaseDigits = BaseHeadCode.SubString(3, 2).ToInt();
14074 int NextRepeatDigits = BaseDigits + (IncDigits * RepeatNumber);
14076 while(NextRepeatDigits >= 100)
14078 NextRepeatDigits -= 100;
14080 AnsiString NextRepeatDigitsStr = AnsiString(NextRepeatDigits);
14082 if(NextRepeatDigitsStr.Length() < 2)
14084 NextRepeatDigitsStr = AnsiString(
'0') + NextRepeatDigitsStr;
14086 AnsiString NextRepeatHeadCode = BaseHeadCode.SubString(1, 2) + NextRepeatDigitsStr;
14089 return(NextRepeatHeadCode);
14097 AnsiString(RepeatNumber) +
"," + AnsiString(IncMinutes));
14098 TDateTime NextRepeatTime = BasicTime + TDateTime(((
double)(RepeatNumber * IncMinutes)) / 1440.0);
14101 return(NextRepeatTime);
14110 AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes));
14111 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
14112 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
14113 int RepeatSecs = RepeatMinutes * 60;
14115 if((ForwardSecs > (ReverseSecs - RepeatSecs + 10)) || (ForwardSecs < (ReverseSecs - RepeatSecs - 10)))
14133 NonRepeatingHeadCode);
14134 int ForwardCount = 0;
14135 int ReverseCount = 0;
14136 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
14146 if(TDEntry.
HeadCode == MainHeadCode)
14148 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
14154 ForwardEntryPtr = &AVEntry;
14156 ForwardTDVectorNumber = x;
14161 if(ForwardCount == 0)
14164 throw Exception(
"Error, ForwardCount == 0 in CheckNonRepeatingShuttleLinksAndSetData after called with found values");
14166 if(ForwardCount > 1)
14168 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + NonRepeatingHeadCode +
" from a train whose headcode is " +
14178 if(TDEntry.
HeadCode == NonRepeatingHeadCode)
14180 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
14187 ReverseEntryPtr = &AVEntry;
14188 ReverseTDVectorNumber = x;
14194 if(ReverseCount == 0)
14196 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + NonRepeatingHeadCode);
14201 if(ReverseCount > 1)
14203 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
14204 NonRepeatingHeadCode);
14209 if(((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh")) && (MainTrainDataPtr->
ActionVector.back().FormatType ==
Repeat))
14211 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle connecting train " + MainHeadCode +
" shouldn't have a repeat");
14216 if((ForwardEntryPtr->Command !=
"F-nshs") && (ForwardEntryPtr->Command !=
"Sns-fsh") && (MainTrainDataPtr->
ActionVector.back().FormatType !=
Repeat))
14218 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat item");
14223 if(ForwardEntryPtr->LocationName ==
"")
14225 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
14226 ". One or other service does not have a location set");
14233 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
14234 ". One or other service does not have a location set");
14239 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
14241 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + NonRepeatingHeadCode +
14242 " is at a different location to the referencing train " + MainHeadCode);
14247 if(ForwardEntryPtr->Command ==
"F-nshs")
14250 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
14252 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle in-link service " + MainHeadCode +
14253 " finish time not consistent with start time of shuttle service " + NonRepeatingHeadCode);
14259 if(ForwardEntryPtr->Command ==
"Fns-sh")
14263 MainTrainDataPtr->
ActionVector.back().RearStartOrRepeatMins, MainTrainDataPtr->
ActionVector.back().NumberOfRepeats))
14265 SecondPassMessage(GiveMessages,
"Error in timetable - service " + NonRepeatingHeadCode +
", which links out from shuttle service " + MainHeadCode +
14266 ", has the wrong start time. It should correspond to the finish time of the last shuttle.");
14272 if((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh"))
14275 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
14277 SecondPassMessage(GiveMessages,
"Error in timetable - the non repeating link service " + NonRepeatingHeadCode +
14278 " appears in the same sequence as the corresponding shuttle service " + MainHeadCode);
14296 if(ForwardEntryPtr->Command ==
"Sns-sh")
14298 if(ReverseEntryPtr->
Command !=
"F-nshs")
14300 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'F-nshs' event for the 'Sns-sh' train whose headcode is " +
14301 MainHeadCode +
" and is a new shuttle service formed from the service with headcode " + NonRepeatingHeadCode);
14307 if(ForwardEntryPtr->Command ==
"F-nshs")
14309 if(ReverseEntryPtr->
Command !=
"Sns-sh")
14311 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns-sh' event for the 'F-nshs' train whose headcode is " +
14312 MainHeadCode +
" and forms a new shuttle service with headcode " + NonRepeatingHeadCode);
14319 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
14330 if(ForwardEntryPtr->Command ==
"Sns-fsh")
14332 if(ReverseEntryPtr->
Command !=
"Fns-sh")
14335 "Error in timetable - unable to find a corresponding 'Fns-sh' event for the 'Sns-fsh' non-shuttle service whose headcode is " + MainHeadCode +
14336 " formed from a shuttle service with headcode " + NonRepeatingHeadCode);
14342 if(ForwardEntryPtr->Command ==
"Fns-sh")
14344 if(ReverseEntryPtr->
Command !=
"Sns-fsh")
14347 "Error in timetable - unable to find a corresponding 'Sns-fsh' event for the 'Fns-sh' shuttle service whose headcode is " + MainHeadCode +
14348 " and forms a new non-shuttle service with headcode " + NonRepeatingHeadCode);
14355 ForwardEntryPtr->NonRepeatingShuttleLinkEntryPtr = OtherTrainDataPtr;
14379 +
"," + AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes) +
"," + AnsiString(RepeatNumber));
14380 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
14381 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
14382 int RepeatSecs = RepeatMinutes * RepeatNumber * 60;
14384 if((ReverseSecs > (ForwardSecs + RepeatSecs + 10)) || (ReverseSecs < (ForwardSecs + RepeatSecs - 10)))
14408 throw Exception(
"Error - last entry in " + TDEntryPtr->
HeadCode +
" service is not a repeat - should have already found this error");
14411 AnsiString OriginalHeadCode = TDEntryPtr->
HeadCode;
14412 AnsiString LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
14414 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
14416 SecondPassMessage(GiveMessages,
"Error in timetable - last event in shuttle service " + TDEntryPtr->
HeadCode +
" is not 'Fns', 'Fns-sh' or 'Frh-sh'");
14421 while(LastActionCommand ==
"Fns")
14423 TDEntryPtr = (TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr;
14424 LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
14425 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
14428 "Error in timetable - last event in a continuation shuttle service (i.e links back to a shuttle) whose headcode is " + TDEntryPtr->
HeadCode +
14429 " is not 'Fns', 'Fns-sh' or 'Frh-sh'");
14436 if((TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr != ShuttleStartAddress)
14439 " is a shuttle finish, but it doesn't link back to the start of the original shuttle starting service " + OriginalHeadCode +
14440 ". The linking of two or more shuttles is not permitted.");
14460 ShowMessage(Message);
14478 ShowMessage(Message);
14517 AnsiString(ActionEventType) +
"," + LocationID);
14518 AnsiString BaseLog =
"", Prefix =
"", ErrorLog =
"", WarningStr =
"";
14523 Prefix =
" ERROR: ";
14526 Prefix =
" HELD: ";
14527 ErrorLog =
" can't enter railway, train obstructing entry position ";
14528 WarningStr =
" can't enter railway, train obstructing entry position ";
14533 Prefix =
" HELD: ";
14534 ErrorLog =
" can't enter railway, route set against it at entry position ";
14535 WarningStr =
" can't enter railway, route set against it at entry position ";
14540 Prefix =
" HELD: ";
14541 ErrorLog =
" can't be created, train obstructing ";
14542 WarningStr =
" can't be created, train obstructing ";
14547 Prefix =
" HELD: ";
14548 ErrorLog =
" can't be created on a locked route at ";
14549 WarningStr =
" can't be created on a locked route at ";
14554 Prefix =
" HELD: ";
14555 ErrorLog =
" can't enter on a locked route at ";
14556 WarningStr =
" can't enter on a locked route at ";
14561 Prefix =
" HELD: ";
14562 ErrorLog =
" can't be created, diverging points at ";
14563 WarningStr =
" can't be created, diverging points at ";
14568 ErrorLog =
" left railway unexpectedly at ";
14573 ErrorLog =
" left railway at an incorrect exit at ";
14578 ErrorLog =
" failed to split - location too short at ";
14579 WarningStr =
" failed to split, location too short at ";
14584 Prefix =
" HELD: ";
14585 ErrorLog =
" unable to split - other train obstructing at ";
14586 WarningStr =
" unable to split - other train obstructing at ";
14591 ErrorLog =
" stopped at buffers unexpectedly at position ";
14595 ErrorLog =
" failed to stop at ";
14600 ErrorLog =
" failed to split at ";
14605 ErrorLog =
" failed to be joined by other train at ";
14610 ErrorLog =
" failed to join other train at ";
14615 ErrorLog =
" failed to terminate at ";
14620 ErrorLog =
" failed to form new service at ";
14625 ErrorLog =
" failed to exit railway ";
14630 ErrorLog =
" failed to change direction at ";
14635 ErrorLog =
" failed to pass ";
14640 ErrorLog =
" facing buffers and unable to start at ";
14644 ErrorLog =
" DERAILED at position ";
14645 Prefix =
" DERAILMENT: ";
14650 ErrorLog =
" CRASHED INTO BUFFERS at ";
14651 Prefix =
" CRASH: ";
14656 ErrorLog =
" CRASHED INTO ROAD TRAFFIC AT A LEVEL CROSSING at ";
14657 Prefix =
" CRASH: ";
14662 ErrorLog =
" CRASHED INTO " + OtherHeadCode +
" at position ";
14663 Prefix =
" CRASH: ";
14667 else if(ActionEventType ==
FailSPAD)
14669 ErrorLog =
" PASSED SIGNAL AT DANGER at position ";
14670 Prefix =
" SPAD: ";
14675 ErrorLog =
"Signals reset ahead of train, route cancelled at position ";
14676 Prefix =
" SPAD RISK: ";
14681 ErrorLog =
" forced a route cancellation by occupying it incorrectly at ";
14685 Prefix =
" WARNING: ";
14686 ErrorLog =
" waiting to join " + OtherHeadCode +
" at ";
14687 WarningStr =
" waiting to join " + OtherHeadCode +
" at ";
14692 Prefix =
" WARNING: ";
14693 ErrorLog =
" waiting to be joined by " + OtherHeadCode +
" at ";
14694 WarningStr =
" waiting to be joined by " + OtherHeadCode +
" at ";
14732 std::ofstream OutFile(
"TrainData.csv");
14736 ShowMessage(
"Output file TrainData.csv failed to open");
14743 OutFile <<
"HeadCode" <<
',' <<
"Description" <<
',' <<
"StartSpeed" <<
',' <<
"MaxRunningSpeed" <<
',' <<
"NumberOfTrains" <<
'\n' <<
'\n';
14748 OutFile <<
',' <<
"FormatType" <<
',' <<
"EventTime" <<
',' <<
"ArrivalTime" <<
',' <<
"DepartureTime" <<
',' <<
"LocationName" <<
',' <<
"Command" <<
14749 ',' <<
"OtherHeadCode" <<
',' <<
"LinkedTrainEntryPtr" <<
',' <<
"RearStartOrRepeatMins" <<
',' <<
"FrontStartOrRepeatDigits" <<
',' <<
14750 "RepeatNumber" <<
'\n' <<
'\n';
14751 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
14754 AnsiString TimetableEntryTypeStr;
14760 TimetableEntryTypeStr =
"NoFormat";
14766 TimetableEntryTypeStr =
"TimeLoc";
14772 TimetableEntryTypeStr =
"TimeTimeLoc";
14778 TimetableEntryTypeStr =
"TimeCmd";
14784 TimetableEntryTypeStr =
"StartNew";
14790 TimetableEntryTypeStr =
"TimeCmdHeadCode";
14796 TimetableEntryTypeStr =
"FinRemHere";
14802 TimetableEntryTypeStr =
"FNSShuttle";
14808 TimetableEntryTypeStr =
"SNTShuttle";
14814 TimetableEntryTypeStr =
"SNSShuttle";
14820 TimetableEntryTypeStr =
"SNSNonRepeatFromShuttle";
14826 TimetableEntryTypeStr =
"FSHNewService";
14832 TimetableEntryTypeStr =
"Repeat";
14838 TimetableEntryTypeStr =
"Default";
14849 OutFile <<
',' <<
',' <<
"Mass" <<
',' <<
"MaxBrakeRate" <<
',' <<
"PowerAtRail" <<
',' <<
"TrainID" <<
',' <<
"RunningEntry" <<
'\n' <<
'\n';
14850 for(
unsigned int y = 0; y <
TrainDataVector.at(x).TrainOperatingDataVector.size(); y++)
14853 AnsiString RunningEntryStr;
14859 RunningEntryStr =
"NotStarted";
14865 RunningEntryStr =
"Running";
14871 RunningEntryStr =
"Exited";
14875 OutFile <<
',' <<
',' << TOD.
TrainID <<
',' << RunningEntryStr.c_str() <<
',' <<
'\n';
14892 ShowMessage(Message);
14893 BaseTime = TDateTime::CurrentDateTime();
14907 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
14920 TTrain *NewTrain =
new TTrain(1, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
14922 for(
int x = 0; x < NumberOfTrains; x++)
14924 *NewTrain =
TTrain(2, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
14944 int NumberOfTrains;
14951 for(
int x = 0; x < NumberOfTrains; x++)
14988 for(
int x = 0; x < LockedRouteVectorSize; x++)
14995 LockedRouteObject.
LockStartTime = TDateTime(LockStartTimeDouble);
15006 int LockedRouteVectorSize;
15013 for(
int x = 0; x < LockedRouteVectorSize; x++)
15071 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
15079 ContinuationAutoSigObject.
PassoutTime = TDateTime(PassoutTimeDouble);
15090 int ContinuationAutoSigVectorSize;
15097 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
15167 if(AVFirstEntry.
Command ==
"Snt")
15191 CTEMMP.second = CTEEntry;
15198 throw Exception(
"Error, Last ActionVectorEntry not a repeat in BuildContinuationTrainExpectationMultiMap");
15206 CTEMMP.second = CTEEntry;
15227 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
15244 if((VecPos < 0) || (VecPos >= (
int)
TrainVector.size()))
15246 throw Exception(
"Out of Range Error, vector size: " + AnsiString(
TrainVector.size()) +
", VecPos: " + AnsiString(VecPos) +
" in TrainVectorAt");
15257 AnsiString RetStr =
"", PartStr =
"";
15372 AnsiString TTFileName = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
15376 TTFileName = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
15378 AnsiString ShortTTName =
"";
15380 for(
int x = TTFileName.Length(); x > 0; x--)
15382 if(TTFileName[x] ==
'\\')
15384 ShortTTName = TTFileName.SubString(x + 1, TTFileName.Length() - x - 4);
15389 ShowMessage(
"Creates two timetables named " + ShortTTName +
15390 " in the 'Formatted timetables' folder, one in service order in '.csv' format, and one in chronological order in '.txt' format");
15392 Screen->Cursor = TCursor(-11);
15394 AnsiString FormatNoDPStr =
"#######0";
15395 AnsiString TableTitle =
"", TimetableTimeStr =
"", MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"", FirstHeadCode =
"", Header =
"";
15398 TableTitle =
"Railway: " + RailwayTitle +
"; Timetable: " + TimetableTitle +
"; Start time: " + TimetableTimeStr;
15405 MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"";
15407 if(TrainDataEntry.
Mass > 0)
15409 MassStr =
"; Mass " + AnsiString::FormatFloat(FormatNoDPStr, ((
double)TrainDataEntry.
Mass) / 1000) +
"Te; ";
15413 PowerStr =
"Power " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
PowerAtRail / 1000 / 0.8) +
"kW; ";
15417 BrakeStr =
"Brake force " + AnsiString::FormatFloat(FormatNoDPStr, (TrainDataEntry.
MaxBrakeRate * TrainDataEntry.
Mass / 9810)) +
"Te; ";
15421 MaxSpeedStr =
"Maximum speed " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
MaxRunningSpeed) +
" km/h";
15423 FirstHeadCode = TrainDataEntry.
HeadCode;
15424 int IncDigits = 0, IncMinutes = 0;
15426 if(!ActionVector.empty())
15428 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
15430 IncDigits = ActionVector.at(ActionVector.size() - 1).FrontStartOrRepeatDigits;
15431 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
15439 if((TrainDataEntry.
Description !=
"") && (MassStr !=
""))
15441 OneTTLine.
Header = TrainDataEntry.
Description + MassStr + PowerStr + BrakeStr + MaxSpeedStr;
15449 for(
unsigned int z = 0; z < ActionVector.size(); z++)
15454 AnsiString PartStr =
"", TimeStr =
"";
15471 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
15475 PartStr =
"Created at " + ActionVectorEntry.
LocationName;
15485 PartStr =
"Enters at " + LocName;
15498 PartStr =
"Created at " + LocName;
15512 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
15517 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
15523 else if(ActionVectorEntry.
Command ==
"Sfs")
15525 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" split from";
15529 else if(ActionVectorEntry.
Command ==
"Sns")
15531 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15539 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15545 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
15553 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15556 AnsiString FirstHeadCode = TDE->
HeadCode;
15560 TimeStr =
GetRepeatHeadCode(36, FirstHeadCode, LastRepeatNumber, IncrementalDigits) +
" at " +
15572 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
15574 OneTTEntry.
Action = PartStr;
15575 OneTTEntry.
Time = TimeStr;
15577 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
15582 PartStr =
"Arrives & departs " + ActionVectorEntry.
LocationName;
15588 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
15593 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
15601 else if(ActionVectorEntry.
Command ==
"jbo")
15603 PartStr =
"Joined at " + ActionVectorEntry.
LocationName +
" by";
15607 else if(ActionVectorEntry.
Command ==
"fsp")
15609 PartStr =
"Splits from front at " + ActionVectorEntry.
LocationName +
" to form";
15613 else if(ActionVectorEntry.
Command ==
"rsp")
15615 PartStr =
"Splits from rear at " + ActionVectorEntry.
LocationName +
" to form";
15619 else if(ActionVectorEntry.
Command ==
"cdt")
15621 PartStr =
"Changes direction at " + ActionVectorEntry.
LocationName;
15627 if(ActionVectorEntry.
Command ==
"Fns")
15629 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15633 else if(ActionVectorEntry.
Command ==
"F-nshs")
15635 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15641 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service ";
15648 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15654 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15661 PartStr =
"Terminates shuttle service at " + ActionVectorEntry.
LocationName;
15666 else if(ActionVectorEntry.
Command ==
"Frh")
15668 PartStr =
"Terminates at " + ActionVectorEntry.
LocationName;
15673 if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
15677 else if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
15687 else if(ActionVectorEntry.
Command ==
"Fer")
15689 AnsiString AllowedExits;
15693 else if(ActionVectorEntry.
Command ==
"Fjo")
15695 PartStr =
"At " + ActionVectorEntry.
LocationName +
" joins";
15704 OneTTEntry.
Action = PartStr;
15705 OneTTEntry.
Time = TimeStr;
15712 AllTTTrains->push_back(OneTTLine);
15716 std::ofstream TTFile(TTFileName.c_str());
15720 StopTTClockMessage(64,
"Formatted timetable file failed to open - can't be created");
15721 delete AllTTTrains;
15756 TTFile << TableTitle.c_str() <<
'\n' <<
'\n';
15757 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
15759 TTFile << AllTTTrains->at(x).Header.c_str();
15762 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
15764 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
15766 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str() <<
',';
15770 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str();
15773 TTFile <<
'\n' <<
'\n';
15775 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.size(); z++)
15777 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.at(z).Action.c_str() <<
',';
15778 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
15780 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
15782 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str() <<
',';
15786 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str();
15791 TTFile <<
'\n' <<
'\n';
15796 AnsiString TTFileName2 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
15798 TTFileName2 = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName2 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".txt";
15800 std::ofstream TTFile2(TTFileName2.c_str());
15804 StopTTClockMessage(67,
"Chronological timetable file failed to open - can't be created");
15805 delete AllTTTrains;
15809 typedef std::multimap<AnsiString, AnsiString>TAnsiMultiMap;
15810 std::multimap<AnsiString, AnsiString>::iterator AMMIT;
15811 std::pair<AnsiString, AnsiString>AnsiMultiMapEntry;
15813 TAnsiMultiMap *TAMM =
new TAnsiMultiMap;
15818 TTFile2 << TableTitle.c_str() <<
'\n' <<
'\n';
15819 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
15821 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
15823 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.size(); z++)
15825 bool GiveMessagesFalse =
false;
15826 AnsiString TimeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time;
15827 AnsiString HeadCodeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode;
15828 AnsiString ActionString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Action;
15833 AnsiString OtherHeadCode = TimeString.SubString(1, 4);
15834 TimeString = TimeString.SubString(9, 5);
15835 ActionString +=
" " + OtherHeadCode;
15837 if(TimeString.SubString(1, 7) ==
"End at ")
15840 TimeString = TimeString.SubString(8, 5);
15842 AnsiString OneLine = TimeString +
' ' + HeadCodeString +
' ' + ActionString +
'\n';
15843 AnsiMultiMapEntry.first = TimeString;
15844 AnsiMultiMapEntry.second = OneLine;
15845 TAMM->insert(AnsiMultiMapEntry);
15850 for(AMMIT = TAMM->begin(); AMMIT != TAMM->end(); AMMIT++)
15852 TTFile2 << (AMMIT->second).c_str();
15854 delete AllTTTrains;
15863 bool AtLocChecked,
int ArrRange,
int DepRange)
15867 bool AnalysisError =
false;
15893 TTrainDataVector::iterator TDVIt, TDVCopyIt;
15895 int IteratorNumber = 0;
15896 AnsiString AnsiSuffix =
"";
15901 for(TDVCopyIt = TrainDataVectorCopy.begin() + IteratorNumber; TDVCopyIt != TrainDataVectorCopy.end(); TDVCopyIt++)
15903 if(TDVCopyIt->ServiceReference == TDVIt->ServiceReference)
15906 AnsiSuffix = AnsiString(Suffix);
15907 TDVCopyIt->ServiceReference = TDVIt->ServiceReference +
"/" + AnsiSuffix;
15914 std::pair<AnsiString, TServiceCallingLocsList> AllServiceCallingLocsEntry;
15915 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
15920 ServiceCallingLocsList.clear();
15921 if(ActionVector.empty())
15925 if(ActionVector.at(0).SignallerControl)
15929 for(
unsigned int z = 0; z < ActionVector.size(); z++)
15947 int HLoc = TE.
HLoc;
15948 int VLoc = TE.
VLoc;
15949 AnsiString HString;
15950 AnsiString VString;
15953 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
15957 HString = AnsiString(HLoc);
15961 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
15965 VString = AnsiString(VLoc);
15967 ServiceCallingLocsList.push_back(HString +
'-' + VString);
15990 else if(AVE.
Command ==
"cdt")
15992 if(ActionVector.at(z-1).SequenceType ==
Start)
15996 else if(ActionVector.at(z+1).SequenceType ==
Finish)
16003 ServiceCallingLocsList.push_back(
"%%%" + TimeString);
16012 ServiceCallingLocsList.push_back(LName);
16016 int HLoc = TE.
HLoc;
16017 int VLoc = TE.
VLoc;
16018 AnsiString HString;
16019 AnsiString VString;
16022 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16026 HString = AnsiString(HLoc);
16030 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16034 VString = AnsiString(VLoc);
16036 ServiceCallingLocsList.push_back(HString +
'-' + VString);
16040 AllServiceCallingLocsEntry.second = ServiceCallingLocsList;
16074 ShowMessage(
"Unable to create a program-readable timetable - please check the timetable file validity");
16080 bool NumPlatsAtThisLocCalculated =
false, ArrivalsPrinted =
false, DeparturesPrinted =
false, AtLocsPrinted =
false;
16081 AnsiString PreviousService =
"", PreviousServiceAndRepeatNumTotalOutput =
"", BasicTime =
"", MinuteString =
"", LastAnsiTime =
"";
16082 int NumTrains = 0, NumPlats = 0, LastFrhCount = 0, FrhCount = 0, NumTrainsAtLoc = 0;
16086 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
16091 TDateTime LastTDTime;
16092 int IncMinutes = 0;
16094 if(ActionVector.empty())
16098 if(ActionVector.at(0).SignallerControl)
16102 if(AVLast->FormatType ==
Repeat)
16104 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
16112 if(AVLast->ArrivalTime != TDateTime(-1))
16114 LastTDTime = AVLast->ArrivalTime;
16116 else if(AVLast->EventTime != TDateTime(-1))
16118 LastTDTime = AVLast->EventTime;
16169 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
16174 int IncMinutes = 0;
16176 if(ActionVector.empty())
16180 if(ActionVector.at(0).SignallerControl)
16184 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
16186 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
16188 for(
int y = 0; y < NumTrains; y++)
16202 for(
unsigned int z = 0; z < ActionVector.size(); z++)
16217 LocServiceTimesVector.push_back(TLSTEntry);
16220 AnsiString IncTime =
"", FoundStopTime =
"";
16221 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16223 if(ActionVector.at(a).FormatType ==
TimeLoc)
16228 if(ActionVector.at(a).SequenceType ==
Finish)
16234 if(FoundStopTime ==
"")
16236 throw Exception(
"Failure to determine FoundStopTime for located Snt");
16238 int WhileCount = 0;
16247 if(IncTime >= FoundStopTime)
16251 LocServiceTimesVector.push_back(TLSTEntry);
16252 if(WhileCount > 2000)
16254 throw Exception(
"While loop failed to break in 2000 loops for located Snt");
16267 int HLoc = TE.
HLoc;
16268 int VLoc = TE.
VLoc;
16269 AnsiString HString;
16270 AnsiString VString;
16273 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16277 HString = AnsiString(HLoc);
16281 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16285 VString = AnsiString(VLoc);
16287 TLSTEntry.
Location = HString +
'-' + VString;
16291 LocServiceTimesVector.push_back(TLSTEntry);
16299 LocServiceTimesVector.push_back(TLSTEntry);
16301 AnsiString IncTime =
"", FoundStopTime =
"";
16302 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16304 if(ActionVector.at(a).FormatType ==
TimeLoc)
16309 if(ActionVector.at(a).SequenceType ==
Finish)
16315 if(FoundStopTime ==
"")
16317 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
16319 int WhileCount = 0;
16328 if(IncTime >= FoundStopTime)
16332 LocServiceTimesVector.push_back(TLSTEntry);
16333 if(WhileCount > 2000)
16335 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
16345 bool SkipAddingMinutes =
false;
16348 LocServiceTimesVector.push_back(TLSTEntry);
16350 AnsiString IncTime =
"", FoundStopTime =
"";
16351 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16353 if(ActionVector.at(a).FormatType ==
TimeLoc)
16358 if(ActionVector.at(a).SequenceType ==
Finish)
16361 if((a == z + 1) && (FoundStopTime == TLSTEntry.
ArrTime) && ((ActionVector.at(a).LinkedTrainEntryPtr > 0) || (ActionVector.at(a).NonRepeatingShuttleLinkEntryPtr > 0)))
16364 LocServiceTimesVector.pop_back();
16365 SkipAddingMinutes =
true;
16370 if(FoundStopTime ==
"")
16372 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
16374 if(!SkipAddingMinutes)
16376 int WhileCount = 0;
16385 if(IncTime >= FoundStopTime)
16389 LocServiceTimesVector.push_back(TLSTEntry);
16390 if(WhileCount > 2000)
16392 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
16401 if((TLSTEntry.
Location == LocServiceTimesVector.back().Location) && (TLSTEntry.
ServiceAndRepeatNum == LocServiceTimesVector.back().ServiceAndRepeatNum))
16403 if(TLSTEntry.
DepTime == LocServiceTimesVector.back().ArrTime)
16405 TLSTEntry.
ArrTime = LocServiceTimesVector.back().ArrTime;
16406 LocServiceTimesVector.pop_back();
16407 LocServiceTimesVector.push_back(TLSTEntry);
16412 LocServiceTimesVector.push_back(TLSTEntry);
16418 LocServiceTimesVector.push_back(TLSTEntry);
16437 LocServiceTimesVector.push_back(TLSTEntry);
16441 AnsiString TempDepTime = TLSTEntry.
DepTime;
16443 LocServiceTimesVector.push_back(TLSTEntry);
16445 while(TLSTEntry.
AtLocTime < TempDepTime)
16450 TLSTEntry.
DepTime = TempDepTime;
16451 LocServiceTimesVector.push_back(TLSTEntry);
16455 LocServiceTimesVector.push_back(TLSTEntry);
16466 LocServiceTimesVector.push_back(TLSTEntry);
16469 LocServiceTimesVector.push_back(TLSTEntry);
16486 AnsiString HString;
16487 AnsiString VString;
16490 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16494 HString = AnsiString(HLoc);
16498 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16502 VString = AnsiString(VLoc);
16504 TLSTEntry.
Location = HString +
'-' + VString;
16506 LocServiceTimesVector.push_back(TLSTEntry);
16511 AnsiString FrhTime;
16512 if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
16516 else if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
16524 LocServiceTimesVector.push_back(TLSTEntry);
16530 LocServiceTimesVector.push_back(TLSTEntry);
16535 else if(AVE.
Command ==
"Frh-sh")
16537 if(y == NumTrains - 1)
16543 LocServiceTimesVector.push_back(TLSTEntry);
16549 LocServiceTimesVector.push_back(TLSTEntry);
16590 TLocServiceTimesVector::iterator Ptr1, Ptr2;
16593 AnsiString TTFileName3 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
16594 TTFileName3 = CurDir +
"\\Formatted timetables\\Conflict Analysis " + TTFileName3 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
16596 std::ofstream TTFile3(TTFileName3.c_str());
16600 ShowMessage(
"Conflict Analysis file failed to open - can't be created");
16604 if(LocServiceTimesVector.empty())
16606 ShowMessage(
"No timetabled services found");
16608 DeleteFile(TTFileName3);
16612 TTFile3 <<
"Timetable analysis for timetable: '" + TimetableTitle +
"' in conjunction with railway: '" + RailwayTitle +
"'\n\n\n";
16619 Ptr1 = LocServiceTimesVector.begin();
16621 while(Ptr2 != LocServiceTimesVector.end())
16623 while(Ptr2->Location == Ptr1->Location)
16626 if(Ptr2 == LocServiceTimesVector.end())
16633 if(Ptr2 != LocServiceTimesVector.end())
16641 TTFile3 <<
"Arrival & pass analysis: an asterisk means that the number of same approach code arrivals and passes is equal to or greater than the number of platforms.\n";
16642 TTFile3 <<
"If the total number of arrivals and passes at the same time exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
16643 MinuteString =
" minutes";
16644 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
16647 MinuteString =
" minute";
16649 TTFile3 <<
"Location,Number of,Number of,Services arriving within " << AnsiString(ArrRange) << MinuteString <<
" with their arrival times and approach codes\n";
16650 TTFile3 <<
",Platforms,Trains\n\n";
16652 Ptr1 = LocServiceTimesVector.begin();
16654 while(Ptr2 != LocServiceTimesVector.end())
16656 PreviousService =
"";
16657 NumTrainsAtLoc = 0;
16658 ServiceAndRepeatNumTotal =
"";
16660 NumPlatsAtThisLocCalculated =
false;
16662 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
16664 PreviousService =
"";
16665 NumTrainsAtLoc = 0;
16666 ServiceAndRepeatNumTotal =
"";
16668 NumPlatsAtThisLocCalculated =
false;
16672 if(Ptr2 == LocServiceTimesVector.end())
16677 if(Ptr2 == LocServiceTimesVector.end())
16681 while(Ptr2->Location == Ptr1->Location)
16683 PreviousService =
"";
16684 NumTrainsAtLoc = 0;
16685 ServiceAndRepeatNumTotal =
"";
16686 BasicTime = Ptr1->ArrTime;
16687 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
16691 while(!
WithinTimeRange(0, BasicTime, Ptr2->ArrTime, ArrRange) || ((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
"")))
16693 BasicTime = Ptr2->ArrTime;
16696 if(Ptr2 == LocServiceTimesVector.end())
16700 if(Ptr2->Location != Ptr1->Location)
16705 if(Ptr2 == LocServiceTimesVector.end())
16709 if(Ptr2->Location != Ptr1->Location)
16715 if((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
""))
16719 if(!NumPlatsAtThisLocCalculated)
16722 NumPlatsAtThisLocCalculated =
true;
16724 if(Ptr1->ServiceAndRepeatNum != PreviousService)
16726 if(ServiceAndRepeatNumTotal ==
"")
16728 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
16729 NumTrainsAtLoc = 1;
16733 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
16736 PreviousService = Ptr2->ServiceAndRepeatNum;
16737 if(ServiceAndRepeatNumTotal ==
"")
16739 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
16740 NumTrainsAtLoc = 1;
16744 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
16748 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(2, BasicTime, Ptr2->ArrTime, ArrRange)))
16750 int MaxNumberOfSameDirections = 0;
16751 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
true, AnalysisError, MaxNumberOfSameDirections);
16756 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
16760 AnsiString Asterisk =
"";
16761 if(MaxNumberOfSameDirections >= NumPlats)
16766 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
16767 ArrivalsPrinted =
true;
16768 ServiceAndRepeatNumTotal =
"";
16770 if(Ptr2 == LocServiceTimesVector.end())
16774 if(Ptr2->Location != Ptr1->Location)
16779 if(Ptr2 == LocServiceTimesVector.end())
16785 if(!ArrivalsPrinted)
16787 TTFile3 <<
"Nothing to report for arrivals";
16789 TTFile3 <<
"\n\n\n";
16797 Ptr1 = LocServiceTimesVector.begin();
16799 while(Ptr2 != LocServiceTimesVector.end())
16801 while(Ptr2->Location == Ptr1->Location)
16804 if(Ptr2 == LocServiceTimesVector.end())
16811 if(Ptr2 != LocServiceTimesVector.end())
16818 TTFile3 <<
"Departure & pass analysis: an asterisk means that the number of same exit code departures and passes is equal to or greater than the number of platforms.\n";
16819 TTFile3 <<
"If the total number of departures and passes at the same time exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
16820 MinuteString =
" minutes";
16821 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
16824 MinuteString =
" minute";
16826 TTFile3 <<
"Location,Number of,Number of,Services departing within " << AnsiString(DepRange) << MinuteString <<
" with their departure times and exit codes\n";
16827 TTFile3 <<
",Platforms,Trains\n\n";
16829 Ptr1 = LocServiceTimesVector.begin();
16831 while(Ptr2 != LocServiceTimesVector.end())
16833 PreviousService =
"";
16834 NumTrainsAtLoc = 0;
16835 ServiceAndRepeatNumTotal =
"";
16837 NumPlatsAtThisLocCalculated =
false;
16839 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
16841 PreviousService =
"";
16842 NumTrainsAtLoc = 0;
16843 ServiceAndRepeatNumTotal =
"";
16845 NumPlatsAtThisLocCalculated =
false;
16849 if(Ptr2 == LocServiceTimesVector.end())
16854 if(Ptr2 == LocServiceTimesVector.end())
16858 while(Ptr2->Location == Ptr1->Location)
16860 PreviousService =
"";
16861 NumTrainsAtLoc = 0;
16862 ServiceAndRepeatNumTotal =
"";
16863 BasicTime = Ptr1->DepTime;
16864 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
16868 while(!
WithinTimeRange(3, BasicTime, Ptr2->DepTime, DepRange) || ((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
"")))
16870 BasicTime = Ptr2->DepTime;
16873 if(Ptr2 == LocServiceTimesVector.end())
16877 if(Ptr2->Location != Ptr1->Location)
16882 if(Ptr2 == LocServiceTimesVector.end())
16886 if(Ptr2->Location != Ptr1->Location)
16892 if((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
""))
16896 if(!NumPlatsAtThisLocCalculated)
16899 NumPlatsAtThisLocCalculated =
true;
16901 if(Ptr1->ServiceAndRepeatNum != PreviousService)
16903 if(ServiceAndRepeatNumTotal ==
"")
16905 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
16906 NumTrainsAtLoc = 1;
16910 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
16913 PreviousService = Ptr2->ServiceAndRepeatNum;
16914 if(ServiceAndRepeatNumTotal ==
"")
16916 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
16917 NumTrainsAtLoc = 1;
16921 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
16925 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(5, BasicTime, Ptr2->DepTime, DepRange)))
16927 int MaxNumberOfSameDirections = 0;
16928 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(3, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
false, AnalysisError, MaxNumberOfSameDirections);
16933 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
16937 AnsiString Asterisk =
"";
16938 if(MaxNumberOfSameDirections >= NumPlats)
16943 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
16944 DeparturesPrinted =
true;
16945 ServiceAndRepeatNumTotal =
"";
16947 if(Ptr2 == LocServiceTimesVector.end())
16951 if(Ptr2->Location != Ptr1->Location)
16956 if(Ptr2 == LocServiceTimesVector.end())
16962 if(!DeparturesPrinted)
16964 TTFile3 <<
"Nothing to report for departures";
16966 TTFile3 <<
"\n\n\n";
16976 Ptr1 = LocServiceTimesVector.begin();
16978 while(Ptr2 != LocServiceTimesVector.end())
16980 while(Ptr2->Location == Ptr1->Location)
16983 if(Ptr2 == LocServiceTimesVector.end())
16990 if(Ptr2 != LocServiceTimesVector.end())
16997 TTFile3 <<
"Trains present at location analysis: an asterisk means that the number of trains at the location is greater than the number of platforms.\n\n";
16998 TTFile3 <<
"Location,Number of,Number of,Time,Services at the location at that time\n";
16999 TTFile3 <<
",Platforms,Trains,\n\n";
17000 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
17001 Ptr1 = LocServiceTimesVector.begin();
17003 while(Ptr2 != LocServiceTimesVector.end())
17005 PreviousService =
"";
17006 ServiceAndRepeatNumTotal =
"";
17007 NumTrainsAtLoc = 0;
17009 NumPlatsAtThisLocCalculated =
false;
17011 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
17013 PreviousService =
"";
17014 ServiceAndRepeatNumTotal =
"";
17015 NumTrainsAtLoc = 0;
17017 NumPlatsAtThisLocCalculated =
false;
17021 if(Ptr2 == LocServiceTimesVector.end())
17026 if(Ptr2 == LocServiceTimesVector.end())
17030 while(Ptr2->Location == Ptr1->Location)
17032 if(Ptr1->FrhMarker ==
"Frh")
17035 Ptr1->FrhMarker =
"FrhCounted";
17037 PreviousService =
"";
17038 NumTrainsAtLoc = 0;
17039 ServiceAndRepeatNumTotal =
"";
17040 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
17044 while((Ptr2->AtLocTime != Ptr1->AtLocTime) || ((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
"")))
17047 if(Ptr1->FrhMarker ==
"Frh")
17050 Ptr1->FrhMarker =
"FrhCounted";
17053 if(Ptr2 == LocServiceTimesVector.end())
17057 if(Ptr2->Location != Ptr1->Location)
17062 if(Ptr2 == LocServiceTimesVector.end())
17066 if(Ptr2->Location != Ptr1->Location)
17070 while(Ptr2->AtLocTime == Ptr1->AtLocTime)
17072 if((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
""))
17076 if(!NumPlatsAtThisLocCalculated)
17079 NumPlatsAtThisLocCalculated =
true;
17081 if(Ptr1->ServiceAndRepeatNum != PreviousService)
17083 if(ServiceAndRepeatNumTotal ==
"")
17085 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum;
17086 NumTrainsAtLoc = 1;
17090 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum;
17093 PreviousService = Ptr2->ServiceAndRepeatNum;
17094 if(ServiceAndRepeatNumTotal ==
"")
17096 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum;
17097 NumTrainsAtLoc = 1;
17101 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum;
17104 if(Ptr1->FrhMarker ==
"Frh")
17107 Ptr1->FrhMarker =
"FrhCounted";
17110 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (Ptr2->AtLocTime != Ptr1->AtLocTime))
17114 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTAtLoc(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc);
17116 if((NumTrainsAtLoc > 1) && ((FrhCount < NumTrainsAtLoc) || (FrhCount != LastFrhCount)))
17118 AnsiString Asterisk =
"";
17119 if(NumTrainsAtLoc > NumPlats)
17126 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
17128 else if(FrhCount == 1)
17130 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (1 remains here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
17134 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (" << FrhCount <<
" remain here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
17136 LastFrhCount = FrhCount;
17137 PreviousServiceAndRepeatNumTotalOutput = ServiceAndRepeatNumTotalOutput;
17138 AtLocsPrinted =
true;
17139 ServiceAndRepeatNumTotal =
"";
17142 if(Ptr2 == LocServiceTimesVector.end())
17146 if(Ptr2->Location != Ptr1->Location)
17151 if(Ptr2 == LocServiceTimesVector.end())
17159 TTFile3 <<
"Nothing to report for trains at locations";
17161 TTFile3 <<
"\n\n\n";
17182 catch(
const Exception &e)
17184 AnsiString TTErrorFileName =
"Analysis Error.txt";
17185 TTErrorFileName = CurDir +
"\\Formatted timetables\\" + TTErrorFileName;
17186 std::ofstream TTError(TTErrorFileName.c_str());
17189 ShowMessage(
"Analysis error file failed to open - can't be created");
17193 AnsiString TimeNow = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
17194 TTError << TimeNow.c_str() <<
"\n" << ArrRange <<
"\n" << ArrChecked <<
"\n" << DepRange <<
"\n" <<
17195 DepChecked <<
"\n" << AtLocChecked <<
"\n" << AnsiString(e.Message);
17197 ShowMessage(
"Error in Conflict Analysis: A file called 'Analysis Error.txt' has been created in your Formatted timetables folder. Please send this file together with your railway and timetable files to railwayfeedback@gmail.com for investigation - many thanks");
17209 if((Time1 ==
"") || (Time2 ==
""))
17214 int Mins = Time1.SubString(4,2).ToInt();
17215 int Hours = Time1.SubString(1,2).ToInt();
17216 int Time1Mins = (Hours * 60) + Mins;
17217 Mins = Time2.SubString(4,2).ToInt();
17218 Hours = Time2.SubString(1,2).ToInt();
17219 int Time2Mins = (Hours * 60) + Mins;
17220 if(abs(Time1Mins - Time2Mins) <= MinuteRange)
17232 bool &AnalysisError,
int &MaxNumberOfSameDirections)
17239 AnsiString Output =
"", OneService =
"", TempStr1 =
"", TempStr2 =
"";
17241 std::list<AnsiString> ServiceList;
17243 bool EvenComma =
false;
17244 for(
int x = 1; x <= Input.Length(); x++)
17246 TempStr1 = Input[x];
17247 if(TempStr1 == AnsiString(
',') && EvenComma)
17253 TempStr2 += Input[x];
17255 if(TempStr1 == AnsiString(
','))
17257 EvenComma = !EvenComma;
17261 while(TempStr2.Length() > 0)
17263 SCPos = TempStr2.Pos(
';');
17266 OneService = TempStr2.SubString(1, SCPos - 1);
17267 ServiceList.push_back(OneService);
17268 TempStr2 = TempStr2.SubString(SCPos + 1, TempStr2.Length() - SCPos);
17272 ServiceList.push_back(TempStr2);
17276 ServiceList.sort();
17277 ServiceList.unique();
17278 NumTrainsAtLoc = ServiceList.size();
17281 int DirectionMarker = 0;
17283 std::list<AnsiString>::iterator SLIt, SLIt1, SLIt2, SLIt3;
17285 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
17287 *SLIt = *SLIt +
"&0";
17289 SLIt3 = ServiceList.end();
17291 AnsiString ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatInfo1, RepeatInfo2;
17292 int AmpersandPos, SpacePos, CommaPos1, CommaPos2, RepeatNum1, RepeatNum2;
17293 TAllServiceCallingLocsMap::iterator ASCLIt1, ASCLIt2;
17295 MaxNumberOfSameDirections = 0;
17296 int SameDirectionCount = 0;
17298 for(std::list<AnsiString>::iterator SLIt1 = ServiceList.begin(); SLIt1 != SLIt3; SLIt1++)
17302 if(SLIt1->SubString(SLIt1->Length() - 1, 2) != AnsiString(
"&0"))
17308 CommaPos1 = SLIt1->Pos(
',');
17309 ServiceRef1 = SLIt1->SubString(1, CommaPos1 - 1);
17311 SpacePos = ServiceRef1.Pos(
' ');
17315 RepeatInfo1 = ServiceRef1.SubString(SpacePos + 2, ServiceRef1.Length() - SpacePos - 2);
17316 ServiceRef1 = ServiceRef1.SubString(1, SpacePos - 1);
17317 if(RepeatInfo1[1] ==
'F')
17323 SpacePos = RepeatInfo1.Pos(
' ');
17324 RepeatNum1 = RepeatInfo1.SubString(SpacePos + 1, RepeatInfo1.Length() - SpacePos).ToInt();
17327 AnsiTime1 = SLIt1->SubString(CommaPos1 + 1, SLIt1->Length() - CommaPos1);
17329 AmpersandPos = AnsiTime1.Pos(
'&');
17330 AnsiTime1 = AnsiTime1.SubString(1, AmpersandPos - 1);
17335 throw Exception(
"ASCLIt1 Error in " + Input);
17337 ServiceCallingLocsList1 = ASCLIt1->second;
17338 AmpersandPos = SLIt1->Pos(
'&');
17339 *SLIt1 = SLIt1->SubString(1, AmpersandPos);
17340 *SLIt1 = *SLIt1 + AnsiString(++DirectionMarker);
17342 SameDirectionCount = 1;
17343 for(SLIt2 = SLIt; SLIt2 != ServiceList.end(); SLIt2++)
17345 CommaPos2 = SLIt2->Pos(
',');
17346 ServiceRef2 = SLIt2->SubString(1, CommaPos2 - 1);
17348 SpacePos = ServiceRef2.Pos(
' ');
17352 RepeatInfo2 = ServiceRef2.SubString(SpacePos + 2, ServiceRef2.Length() - SpacePos - 2);
17353 ServiceRef2 = ServiceRef2.SubString(1, SpacePos - 1);
17354 if(RepeatInfo2[1] ==
'F')
17360 SpacePos = RepeatInfo2.Pos(
' ');
17361 RepeatNum2 = RepeatInfo2.SubString(SpacePos + 1, RepeatInfo2.Length() - SpacePos).ToInt();
17364 AnsiTime2 = SLIt2->SubString(CommaPos2 + 1, SLIt2->Length() - CommaPos2);
17366 AmpersandPos = AnsiTime2.Pos(
'&');
17367 AnsiTime2 = AnsiTime2.SubString(1, AmpersandPos - 1);
17372 throw Exception(
"ASCLIt2 Error in " + Input);
17374 ServiceCallingLocsList2 = ASCLIt2->second;
17376 if(
SameDirection(0, ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatNum1, RepeatNum2, ServiceCallingLocsList1, ServiceCallingLocsList2, Location, Arrival))
17378 int AmpersandPos = SLIt2->Pos(
'&');
17379 *SLIt2 = SLIt2->SubString(1, AmpersandPos);
17380 *SLIt2 = *SLIt2 + AnsiString(DirectionMarker);
17381 SameDirectionCount++;
17384 if(SameDirectionCount > MaxNumberOfSameDirections)
17386 MaxNumberOfSameDirections = SameDirectionCount;
17391 if(SLIt3->SubString(SLIt3->Length() - 1, 2) == AnsiString(
"&0"))
17394 AmpersandPos = SLIt3->Pos(
'&');
17395 *SLIt3 = SLIt3->SubString(1, AmpersandPos);
17396 *SLIt3 = *SLIt3 + AnsiString(++DirectionMarker);
17399 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
17402 AmpersandPos = SLIt->Pos(
'&');
17403 AnsiString DirectionMarkerString = SLIt->SubString(AmpersandPos + 1, SLIt->Length() - AmpersandPos);
17404 AnsiString ServiceWithoutMarker = SLIt->SubString(1, AmpersandPos - 1);
17405 DirectionMarker = DirectionMarkerString.ToInt();
17406 AnsiString DirectionSuffix =
"";
17408 if(DirectionMarker < 27)
17410 c = 64 + DirectionMarker;
17411 DirectionSuffix =
"," + AnsiString(c);
17413 else if(DirectionMarker < 53)
17415 c = 65 + DirectionMarker - 27;
17416 DirectionSuffix =
",A" + AnsiString(c);
17420 DirectionSuffix =
",?";
17422 *SLIt = ServiceWithoutMarker + DirectionSuffix;
17425 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
17427 Output = Output + *SLIt +
",";
17429 if(Output.Length() > 0)
17431 Output = Output.SubString(1, Output.Length() - 1);
17437 catch(
const Exception &e)
17439 AnalysisError =
true;
17451 AnsiString InternalInput = Input, Output =
"", OneService =
"";
17453 std::list<AnsiString> ServiceList;
17455 while(InternalInput.Length() > 0)
17457 CommaPos = InternalInput.Pos(
',');
17460 OneService = InternalInput.SubString(1, CommaPos - 1);
17461 ServiceList.push_back(OneService);
17462 InternalInput = InternalInput.SubString(CommaPos + 1, InternalInput.Length() - CommaPos);
17466 ServiceList.push_back(InternalInput);
17467 InternalInput =
"";
17471 ServiceList.sort();
17472 ServiceList.unique();
17473 NumTrainsAtLoc = ServiceList.size();
17474 for(std::list<AnsiString>::iterator SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
17476 Output = Output + *SLIt +
",";
17478 if(Output.Length() > 0)
17480 Output = Output.SubString(1, Output.Length() - 1);
17493 AnsiString(RepeatNum1) +
"," + AnsiString(RepeatNum2) +
"," + Location);
17495 std::list<AnsiString>::iterator LP1 = 0, LP2 = 0, ListPtr1 = 0, ListPtr2 = 0, LocPtr1 = 0, LocPtr2 = 0;
17500 bool LocFound =
false;
17501 AnsiString Ref1 = Ref1In, Ref2 = Ref2In;
17503 TDateTime FirstServiceTime;
17506 int Ref1Target = 0, Ref1Count = 0;
17507 int SlashPos = Ref1.Pos(
'/');
17510 Ref1Target = Ref1.SubString(SlashPos + 1, Ref1.Length() - SlashPos).ToInt();
17511 Ref1 = Ref1.SubString(1, SlashPos - 1);
17513 int Ref2Target = 0, Ref2Count = 0;
17514 SlashPos = Ref2.Pos(
'/');
17517 Ref2Target = Ref2.SubString(SlashPos + 1, Ref2.Length() - SlashPos).ToInt();
17518 Ref2 = Ref2.SubString(1, SlashPos - 1);
17520 for(ListPtr1 = List1.begin(); ListPtr1 != List1.end(); ListPtr1++)
17523 if((*ListPtr1) == Location)
17525 LocPtr1 = ListPtr1;
17528 if(ListPtr1->SubString(1, 3) ==
"%%%")
17530 AnsiString CDTTime = ListPtr1->SubString(4, 5);
17535 FirstServiceTime = TDateTime(-1);
17536 bool BreakFlag =
false;
17539 if(TDVIt->ServiceReference == Ref1)
17541 if(Ref1Target > Ref1Count)
17546 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
17547 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
17551 FirstServiceTime = AVIt->EventTime;
17557 FirstServiceTime = AVIt->ArrivalTime;
17563 FirstServiceTime = AVIt->DepartureTime;
17574 if(IncMinutes == -1)
17576 throw Exception(
"Failed to find service for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
17578 if(FirstServiceTime == TDateTime(-1))
17580 throw Exception(
"Failed to find first service time for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
17584 if(!Arrival && (Time1 == CDTTime))
17589 if(Arrival && (Time1 == CDTTime))
17593 if(Time1 > CDTTime)
17598 if(Time1 < CDTTime)
17611 for(ListPtr2 = List2.begin(); ListPtr2 != List2.end(); ListPtr2++)
17613 if((*ListPtr2) == Location)
17615 LocPtr2 = ListPtr2;
17618 if(ListPtr2->SubString(1, 3) ==
"%%%")
17620 AnsiString CDTTime = ListPtr2->SubString(4, 5);
17625 FirstServiceTime = TDateTime(-1);
17626 bool BreakFlag =
false;
17629 if(TDVIt->ServiceReference == Ref2)
17631 if(Ref2Target > Ref2Count)
17636 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
17637 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
17641 FirstServiceTime = AVIt->EventTime;
17647 FirstServiceTime = AVIt->ArrivalTime;
17653 FirstServiceTime = AVIt->DepartureTime;
17664 if(IncMinutes == -1)
17666 throw Exception(
"IncMinutes -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
17668 if(FirstServiceTime == TDateTime(-1))
17670 throw Exception(
"First service time -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
17674 if(!Arrival && (Time2 == CDTTime))
17679 if(Arrival && (Time2 == CDTTime))
17683 if(Time2 > CDTTime)
17688 if(Time2 < CDTTime)
17703 LP1 = List1.begin();
17705 for(ListPtr1 = LocPtr1; ListPtr1 != LP1; ListPtr1--)
17707 if(ListPtr1 == List1.begin())
17711 if(ListPtr1->SubString(1, 3) ==
"%%%")
17718 LP2 = List2.begin();
17720 for(ListPtr2 = LocPtr2; ListPtr2 != LP2; ListPtr2--)
17722 if(ListPtr2 == List2.begin())
17726 if(ListPtr2->SubString(1, 3) ==
"%%%")
17736 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
17738 if(ListPtr1 == LocPtr1)
17742 if(ListPtr1->SubString(1, 3) ==
"%%%")
17746 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
17748 if(ListPtr2 == LocPtr2)
17752 if(ListPtr2->SubString(1, 3) ==
"%%%")
17756 if((*ListPtr1) == (*ListPtr2))
17773 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
17775 if(ListPtr1 == List1.end())
17779 if(ListPtr1->SubString(1, 3) ==
"%%%")
17783 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
17785 if(ListPtr2 == List2.end())
17789 if(ListPtr2->SubString(1, 3) ==
"%%%")
17793 if((*ListPtr1) == (*ListPtr2))
17810 if(ExitList.empty())
17816 AnsiString ExitLocList =
"";
17819 unsigned int Counter = 0;
17824 if(((Counter % 6) == 0) && (Counter < (ExitList.size() - 1)))
17826 ExitLocList +=
"\n";
17829 if(StartName ==
"")
17831 if(ExitList.size() == 1)
17835 return(
" at " + ID);
17840 if(ExitList.size() < 4)
17842 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
17847 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
17857 if(ExitList.size() < 4)
17859 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
17864 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
17870 if(ExitList.size() < 4)
17872 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
17873 return(
" at " + StartName);
17877 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
17878 return(
" at " + StartName);
17918 AnsiString FormatStr =
"####0.0";
17919 AnsiString AvLateArrMins =
"";
17920 AnsiString AvEarlyArrMins =
"";
17921 AnsiString AvLatePassMins =
"";
17922 AnsiString AvEarlyPassMins =
"";
17923 AnsiString AvLateDepMins =
"";
17924 AnsiString AvLateExitMins =
"";
17925 AnsiString AvEarlyExitMins =
"";
17955 PerfFile <<
'\n' <<
'\n' <<
"***************************************";
17956 PerfFile <<
'\n' <<
'\n' <<
"Performance summary:" <<
'\n';
17968 PerfFile <<
LateArrivals <<
" late arrivals (average " << AvLateArrMins.c_str() <<
" min)" <<
'\n';
17972 PerfFile <<
LateArrivals <<
" late arrival (" << AvLateArrMins.c_str() <<
" min)" <<
'\n';
17980 PerfFile <<
EarlyArrivals <<
" early arrivals (average " << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
17984 PerfFile <<
EarlyArrivals <<
" early arrival (" << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
17992 PerfFile <<
OnTimePasses <<
" on-time passes" <<
'\n';
18000 PerfFile <<
LatePasses <<
" late passes (average " << AvLatePassMins.c_str() <<
" min)" <<
'\n';
18004 PerfFile <<
LatePasses <<
" late pass (" << AvLatePassMins.c_str() <<
" min)" <<
'\n';
18008 PerfFile <<
LatePasses <<
" late passes" <<
'\n';
18012 PerfFile <<
EarlyPasses <<
" early passes (average " << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
18016 PerfFile <<
EarlyPasses <<
" early pass (" << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
18020 PerfFile <<
EarlyPasses <<
" early passes" <<
'\n';
18025 PerfFile <<
OnTimeExits <<
" on-time exits" <<
'\n';
18029 PerfFile <<
OnTimeExits <<
" on-time exit" <<
'\n';
18033 PerfFile <<
LateExits <<
" late exits (average " << AvLateExitMins.c_str() <<
" min)" <<
'\n';
18037 PerfFile <<
LateExits <<
" late exit (" << AvLateExitMins.c_str() <<
" min)" <<
'\n';
18041 PerfFile <<
LateExits <<
" late exits" <<
'\n';
18045 PerfFile <<
EarlyExits <<
" early exits (average " << AvEarlyExitMins.c_str() <<
" min)" <<
'\n';
18049 PerfFile <<
EarlyExits <<
" early exit (" << AvEarlyExitMins.c_str() <<
" min)" <<
'\n';
18053 PerfFile <<
EarlyExits <<
" early exits" <<
'\n';
18058 PerfFile <<
OnTimeDeps <<
" on-time departures" <<
'\n';
18062 PerfFile <<
OnTimeDeps <<
" on-time departure" <<
'\n';
18066 PerfFile <<
LateDeps <<
" late departures (average " << AvLateDepMins.c_str() <<
" min)" <<
'\n';
18070 PerfFile <<
LateDeps <<
" late departure (" << AvLateDepMins.c_str() <<
" min)" <<
'\n';
18074 PerfFile <<
LateDeps <<
" late departures" <<
'\n';
18076 TDateTime TempExcessLCDownTime;
18090 if(TempExcessLCDownTime > TDateTime(0))
18096 AnsiString FormattedExcessLCDownMins = FormatFloat(FormatStr,
ExcessLCDownMins);
18100 PerfFile << FormattedExcessLCDownMins.c_str() <<
" excess minutes of level crossing barrier down time" <<
'\n';
18104 PerfFile <<
MissedStops <<
" missed stops" <<
'\n';
18108 PerfFile <<
MissedStops <<
" missed stop" <<
'\n';
18136 PerfFile <<
NumFailures <<
" train failures" <<
'\n';
18140 PerfFile <<
NumFailures <<
" train failure" <<
'\n';
18146 PerfFile <<
AvHoursIntValue <<
" hour mean time betweeen train failures" <<
'\n';
18150 PerfFile <<
AvHoursIntValue <<
" hours mean time betweeen train failures" <<
'\n';
18153 AnsiString AvLateMinsLocsNotReached =
"";
18159 if(LocsNotReached > 0)
18162 PerfFile << LocsNotReached <<
" locations that trains failed to reach (average lateness " << AvLateMinsLocsNotReached.c_str() <<
" min)" <<
'\n';
18166 PerfFile <<
SPADRisks <<
" SPAD risks" <<
'\n';
18170 PerfFile <<
SPADRisks <<
" SPAD risk" <<
'\n';
18182 PerfFile <<
Derailments <<
" derailments" <<
'\n';
18186 PerfFile <<
Derailments <<
" derailment" <<
'\n';
18196 PerfFile <<
'\n' <<
"***************************************" <<
'\n';
18198 bool DerailSPADFlag =
false, CrashFlag =
false;
18200 int OverallScorePercent = 100;
18201 int TotArrDepExit = 0;
18202 double TotLateMinsFactor = 1;
18203 double MissedStopAndSPADRiskFactor = 1;
18204 double NetNegFactor = 1;
18214 OverallScorePercent = 5;
18215 DerailSPADFlag =
true;
18219 OverallScorePercent = 0;
18222 if(OverallScorePercent == 100)
18224 if(TotArrDepExit > 0)
18226 TotLateMinsFactor =
18234 NetNegFactor = TotLateMinsFactor * MissedStopAndSPADRiskFactor;
18236 OverallScorePercent = 100 * NetNegFactor;
18239 if((TotArrDepExit > 0) || DerailSPADFlag || CrashFlag)
18242 AnsiString OneFailureString =
", though the failure would account for some poor performance";
18243 AnsiString TwoOrMoreFailureString =
", though the failures would account for some poor performance";
18244 AnsiString AddedString =
"";
18247 AddedString = OneFailureString;
18251 AddedString = TwoOrMoreFailureString;
18253 PerfFile <<
"\nOverall score: " << OverallScorePercent <<
"%\n";
18254 AnsiString Rating =
"";
18255 if(OverallScorePercent == 100)
18257 Rating =
"Perfect!";
18259 else if(OverallScorePercent >= 95)
18261 Rating =
"Excellent";
18263 else if(OverallScorePercent >= 90)
18265 Rating =
"Very good";
18267 else if(OverallScorePercent >= 80)
18271 else if(OverallScorePercent >= 70)
18275 else if(OverallScorePercent >= 60)
18277 Rating =
"Unacceptable" + AddedString;
18279 else if(OverallScorePercent >= 50)
18281 Rating =
"Poor" + AddedString;
18283 else if(OverallScorePercent >= 40)
18285 Rating =
"Bad" + AddedString;
18287 else if(OverallScorePercent >= 30)
18289 Rating =
"Very bad" + AddedString;
18291 else if(OverallScorePercent >= 20)
18293 Rating =
"Terrible" + AddedString;
18295 else if(OverallScorePercent >= 10)
18297 Rating =
"Appalling" + AddedString;
18299 else if(OverallScorePercent >= 5)
18303 Rating =
"Disastrous - potential loss of life";
18308 Rating =
"Dire" + AddedString;
18311 else if(OverallScorePercent < 5)
18315 Rating =
"Catastrophic - loss of life";
18319 Rating =
"Abysmal";
18322 PerfFile <<
"Overall rating: " << Rating.c_str() <<
'\n';
18326 PerfFile <<
"\nThere were no timetabled departures, arrivals or exits so there is insufficient information to provide a performance score or rating" <<
'\n';
18328 PerfFile <<
'\n' <<
"***************************************";
18337 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
18387 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
18422 int IncrementalMinutes = 0;
18436 bool TrainOperatingFlag =
false;
18441 TrainOperatingFlag =
true;
18445 if(TrainOperatingFlag)
18453 for(
unsigned int z = 0; z < TDEntry.
ActionVector.size(); z++)
18500 AnsiString HeadCode;
18504 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
18508 HCandTrainPosParam.first = HeadCode;
18509 HCandTrainPosParam.second = TrainID;
18511 if((TimeToAct >= 0) && (TimeToAct < 59.9))
18514 OpTimeToActMultiMapEntry.first = TimeToAct;
18515 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
18544 float TimeToAct = 0;
18545 int DistanceToRedSignal = 0;
18548 ContinuationEntryVecPosVector.clear();
18549 bool LaterTrain =
false;
18553 LaterTrain =
false;
18554 if(CTEIt->second.TrainDataEntryPtr->TrainOperatingDataVector.at(CTEIt->second.RepeatNumber).RunningEntry !=
NotStarted)
18565 if(!ContinuationEntryVecPosVector.empty())
18567 for(
unsigned int x = 0; x < ContinuationEntryVecPosVector.size(); x++)
18569 if(CTEIt->second.VectorPosition == ContinuationEntryVecPosVector.at(x))
18583 ContinuationEntryVecPosVector.push_back(CTEIt->second.VectorPosition);
18584 AnsiString HeadCode = CTEIt->second.HeadCode;
18585 float CurrentStopTime;
18586 float LaterStopTime;
18587 float RecoverableTime;
18590 bool SigControlAndCanPassRedSignal =
false;
18594 SigControlAndCanPassRedSignal, &CTEIt->second.TrainDataEntryPtr->ActionVector.at(1),
18596 HeadCode, TrainID, CurrentStopTime, LaterStopTime, RecoverableTime, AvTrackSpeed);
18599 if(AvTrackSpeed < 30)
18603 if(DistanceToRedSignal == -1)
18609 int Speed = AvTrackSpeed;
18610 int MaxSpeed = int(CTEIt->second.TrainDataEntryPtr->MaxRunningSpeed);
18611 if(AvTrackSpeed > MaxSpeed)
18615 if(CTEIt->second.TrainDataEntryPtr->ActionVector.at(1).SignallerControl)
18618 Speed = CTEIt->second.TrainDataEntryPtr->SignallerSpeed;
18621 TimeToAct = LaterStopTime + DistanceToRedSignal * 3.6 / 60 / Speed;
18626 float MinsBefEnter = double(CTEIt->first -
TTClockTime) * 86400.0 / 60.0;
18627 TimeToAct += MinsBefEnter;
18630 HCandTrainPosParam.first = HeadCode;
18631 HCandTrainPosParam.second = -1 - CTEIt->second.VectorPosition;
18634 if(TimeToAct < 59.9)
18636 OpTimeToActMultiMapEntry.first = TimeToAct;
18637 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
18649 bool SigControlAndCanPassRedSignal,
TActionVectorEntry *AVPtr, AnsiString HeadCode,
int TrainID,
float &CurrentStopTime,
float &LaterStopTime,
18650 float &RecoverableTime,
int &AvTrackSpeed)
18659 AnsiString(TrackVectorPositionEntryPos) +
", " + AVPtr->
Command);
18660 int DistanceToRedSignal = 0;
18661 int CumTrackSpeed = 0;
18663 int TrackSpeedCount = 0;
18673 int CurrentElement = TrackVectorPosition;
18674 int CurrentEntryPos = TrackVectorPositionEntryPos;
18679 CurrentStopTime = 0;
18681 RecoverableTime = 0;
18682 if(CurrentElement == -1)
18687 int CurrentExitPos;
18692 if((CurrentEntryPos == 0) || (CurrentEntryPos == 2))
18696 CurrentExitPos = 1;
18700 CurrentExitPos = 3;
18705 CurrentExitPos = 0;
18741 CurrentStopTime = float(TimeToDepart);
18747 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
18758 else if(SigControlAndCanPassRedSignal)
18763 if((NextEntryPos == 0) || (NextEntryPos == 2))
18784 CurrentElement = NextElement;
18785 CurrentEntryPos = NextEntryPos;
18786 CurrentExitPos = NextExitPos;
18798 int LaterStopNumber = 0;
18802 while(!((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0)))
18811 if(CurrentEntryPos > 1)
18831 bool StopRequired =
false;
18848 int TrainOnElement;
18855 if(CurrentEntryPos > 1)
18864 if((TrainOnElement > -1) && (TrainOnElement != TrainID))
18873 double StopTimeDouble;
18886 if(StopTimeDouble < 0.5)
18888 StopTimeDouble = 0.5;
18892 LaterStopTime += float(StopTimeDouble);
18893 RecoverableTime += StopTimeDouble - 0.5;
18894 if((LaterStopNumber == 1) && (TrainID > -1))
18902 if((AVPtr + 1)->FormatType ==
TimeLoc)
18906 StopTimeDouble = double((AVPtr + 1)->DepartureTime - AVPtr->
ArrivalTime) * 86400.0 / 60.0;
18908 if(StopTimeDouble < 0.5)
18910 StopTimeDouble = 0.5;
18913 LaterStopTime += float(StopTimeDouble);
18914 RecoverableTime += StopTimeDouble - 0.5;
18915 if((LaterStopNumber == 1) && (TrainID > -1))
18931 if(NextElement == -1)
18940 if((NextEntryPos == 0) || (NextEntryPos == 2))
18961 CurrentElement = NextElement;
18962 CurrentEntryPos = NextEntryPos;
18963 CurrentExitPos = NextExitPos;
18967 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
18982 float MaxAllowableSpeed;
18984 if(TrackSpeedCount > 0)
18986 MaxAllowableSpeed = CumTrackSpeed / TrackSpeedCount;
18990 if(CurrentEntryPos > 1)
19000 float KmPerLocationStop;
19002 if(LaterStopNumber > 0)
19004 KmPerLocationStop = float(DistanceToRedSignal) / LaterStopNumber / 1000;
19005 AvTrackSpeed = (8.75 * KmPerLocationStop) + 44;
19009 AvTrackSpeed = (sqrt(
float(DistanceToRedSignal) / 1000) * 44) + 60;
19013 if(AvTrackSpeed > MaxAllowableSpeed)
19015 AvTrackSpeed = MaxAllowableSpeed;
19018 return(DistanceToRedSignal);